POJ 3254

应该算做记忆化搜索的

不种也算做一种方案

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include <set>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define mod 100000000
#define ll long long
ll dp[(1<<13)+100][13];
int m,n,a[15][15],ans;

ll dfs(int i,int j,int left,int now)
{
	if(i==m+1)
		return dp[now][n-j]=dfs(1,j+1,now,0)%mod;
	if(j==n+1)
		return 1;
	if(dp[left][n-j+1]!=-1)
		return dp[left][n-j+1];
	ll ret=dfs(i+1,j,left,now)%mod;
	if(a[i][j] && !(left&(1<<i)) && !(now&(1<<(i-1))))
		ret+=dfs(i+1,j,left,now|(1<<i))%mod;
	return ret%mod;
}

int main ()
{
	
	while(scanf("%d%d",&m,&n)!=EOF)
	{
		memset(dp,-1,sizeof(dp));
		memset(a,0,sizeof(a));
		for(int i=1;i<=m;++i)
			for(int j=1;j<=n;++j)
				scanf("%d",&a[i][j]);
		ll ans=dfs(1,1,0,0);
		cout<<ans<<endl;
	}
	return 0;
}

你可能感兴趣的:(POJ 3254)