一道好水的题...还是写篇博客吧...

题目链接

题意:求用\(1*2\)的矩形完全覆盖\(n*m\)的棋盘的方案数。
轮廓线DP入门。
另外可以DFS预处理哪些状态能转移到哪些状态,就不用每次\(2^m\)枚举了。反正复杂度还是\(O(nm2^m)\),不改了。

一个代码看了半小时还是十分感觉它不对,怀疑自己智商ing=-=。

//388K	16MS
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
const int N=11;

LL f[2][(1<<N)+1];

int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m),n&&m)
	{
		if(n*m&1) {puts("0"); continue;}
		if(n<m) std::swap(n,m);
		int lim=(1<<m)-1,p=1;
		memset(f[p],0,sizeof f[p]);
		f[p][lim]=1;
		for(int i=0; i<n; ++i)
			for(int j=0; j<m; ++j)
			{
				p^=1; memset(f[p],0,sizeof f[p]);
				for(int s=0; s<=lim; ++s)
				{
					f[p][s^(1<<j)]+=f[p^1][s];
					if(j && s>>j&1 && !((s>>j-1)&1)) f[p][s|(1<<j-1)]+=f[p^1][s];
				}
			}
		printf("%lld\n",f[p][lim]);
	}
	return 0;
}

相关文章:

  • 2021-12-20
  • 2022-12-23
  • 2022-01-03
  • 2021-08-16
  • 2021-07-29
  • 2021-05-19
  • 2021-07-16
猜你喜欢
  • 2021-05-22
  • 2022-03-01
  • 2021-12-18
  • 2022-01-12
  • 2021-06-13
  • 2021-10-11
  • 2021-10-21
相关资源
相似解决方案