题意:用1*2的方格填充m*n的方格不能重叠,问有多少种填充方法

分析:dp[i][j]表示i行状态为j时的方案数,对于j,0表示该列竖放(影响下一行的该列),1表示横放成功(影响下一列)或上一列竖放成功。状态转移时,枚举每一行可能的状态上一行取反得下一行能放的状态。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = 1000000007;
int n,m;
ll dp[15][1<<11],x;
//枚举可能的状态
void dfs(int i,int j,int p){
if(p==m){
dp[i][j]+=x;
return;
}
dfs(i,j,p+1);
if(p+2<=m&&!(j&(1<<p))&&!(j&(1<<(p+1))))
dfs(i,(j|(1<<p)|(1<<(p+1))),p+2);
}
void solve(){
memset(dp,0,sizeof(dp));
x=1;
dfs(1,0,0);
ll cas=(1<<m);
//x为上一行可能的方案总数
for(int i=2;i<=n;++i){
for(int j=0;j<cas;++j){
if(dp[i-1][j]){
x=dp[i-1][j];
dfs(i,~j&(cas-1),0);
}
}
}
printf("%I64d\n",dp[n][cas-1]);
}
int main()
{
while(~scanf("%d%d",&n,&m)){
if(n==0&&m==0)break;
solve();
}
return 0;
}

  

最新文章

  1. NGif, Animated GIF Encoder for .NET
  2. php 本周开始时间和结束时间;本月开始时间结束时间;上月开始时间结束时间
  3. Httpservlet cannot be resolved to a type的原因与解决方法
  4. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
  5. jQuery+css+div--一些细节详解
  6. Highcharts20151130
  7. ThinkPHP CURD方法盘点:data方法
  8. NSStringUIImage~NSData的相互转换以及中文转码
  9. javase
  10. vue-cli环境配置
  11. MySQL 通讯协议
  12. java web (sevlet)请求之get,post,forward,redirect
  13. VSCode远程调试Go程序方法(Attach)
  14. hiho 第二周
  15. Why does Http header contains &quot;X-SourceFiles&quot;?
  16. SQL注入 payload 记录
  17. Linux 查看内存插槽数、最大容量的方法
  18. Nginx rewrite使用
  19. luogu P3383 【模板】线性筛素数
  20. Flexible 弹性盒子模型之CSS order 属性

热门文章

  1. VisualSvn Server介绍
  2. @JsonFormat时间不对
  3. 【PHPsocket编程专题(实战篇②)】兼容 Curl/Socket/Stream 的 HTTP 操作类[转]
  4. git Unstaged changes after reset
  5. 从一点儿不会开始——Unity3D游戏开发学习(一)
  6. Qt中如何写一个model
  7. Lumina将是基于 Qt工具箱,旨在取代KDE成为PC-BSD默认的桌面环境
  8. 如何获取多核、多cpu系统中指定cpu的序列号
  9. Android:Context的作用
  10. Qt学习记录--Qt::CaseSensitive