状态压缩 dp

dp[i][j] 为第 i 行状态为 j 的总数

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 2005
#define INF 0x3f3f3f3f
#define inf 10000000
#define MOD 100000000
#define ULL unsigned long long
#define LL long long using namespace std; int dp[15][1 << 13], mapp[1 << 13], sta[1 << 13];
int n, m, num; void init() {
memset(dp, 0, sizeof(dp));
memset(mapp, 0, sizeof(mapp));
num = 0;
for(int i = 0; i < (1<<m); ++ i) {
int d = i&(i << 1);
if(d == 0) sta[num++] = i;
}
// printf("num : %d\n", num);
} int main()
{
while(scanf("%d%d", &n, &m) == 2) {
init();
// puts("*********************");
// for(int i = 0; i < num; ++ i) {
// printf("%d ", sta[i]);
// }
// puts("**********************");
for(int i = 0; i < n; ++ i) {
for(int j = 0; j < m; ++ j) {
int a;
scanf("%d", &a);
if(a == 0) mapp[i] = mapp[i]|(1 << j);
}
}
for(int i = 0; i < num; ++ i) {
if((mapp[0] & sta[i]) == 0) {
dp[0][i] = 1;
}
}
for(int i = 1; i < n; ++ i) {
for(int j = 0; j < num; ++ j) {
if(mapp[i-1] & sta[j]) continue;
for(int q = 0; q < num; ++ q) {
if(mapp[i]&sta[q] || sta[j]&sta[q]) continue;
dp[i][q] += dp[i-1][j];
dp[i][q] %= MOD;
}
}
}
int ans = 0;
for(int i = 0; i < num; ++ i) {
ans += dp[n-1][i];
ans %= MOD;
}
printf("%d\n", ans);
}
return 0;
}

  

poj 3254的更多相关文章

  1. poj 3254 状压dp入门题

    1.poj 3254  Corn Fields    状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...

  2. 状压DP POJ 3254 Corn Fields

    题目传送门 /* 状态压缩DP:先处理硬性条件即不能种植的,然后处理左右不相邻的, 接着就是相邻两行查询所有可行的种数并累加 写错一个地方差错N久:) 详细解释:http://www.tuicool. ...

  3. POJ 3254 Corn Fields(状压DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13732   Accepted: 7216 Desc ...

  4. poj 3254 Corn Fields 国家压缩dp

    意甲冠军: 要在m行n陆行,有一些格您可以种树,别人做不到的.不相邻的树,我问了一些不同的共同拥有的法律. 分析: 从后往前种,子问题向父问题扩展,当种到某一格时仅仅有他和他后面的n-1个格子的情况对 ...

  5. Corn Fields POJ - 3254 (状压dp)

    题目链接: Corn Fields  POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...

  6. poj 3254(状态压缩DP)

    poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...

  7. poj - 3254 - Corn Fields (状态压缩)

    poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. poj 3254 Corn Fields

    http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  10. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

随机推荐

  1. 【转】Spark性能测试报告

    RDD可以很好地适用于支持数据并行的批量分析应用,包括数据挖掘,机器学习,图算法等,因为这些程序通常都会在很多记录上执行相同的操作.RDD不太适合那些异步更新共享状态的应用,例如并行web爬行器.因此 ...

  2. pyenv

    export PYTHON_BUILD_MIRROR_URL="http://pyenv.qiniudn.com/pythons/"

  3. 理解ruby on rails中的ActiveRecord::Relation

    ActiveRecord::Relation是rails3中添加的.rails2中的finders, named_scope, with_scope 等用法,在rails3统一为一种Relation用 ...

  4. 在WPF中显示GIF图片并实现循环播放

    WPF中有一个MediaElement媒体控件,可以来播放媒体,同时也可以显示GIF图片.但看到网上有些人说用MediaElement不能加载作为资源或内嵌的资源的GIF图片,我猜他们一定是在前台用X ...

  5. char const*, char*const, const char *const的区别

    C++标准规定,const关键字放在类型或变量名之前等价的.所以,const char*和 char const*是一样的. const char*   //常量指针---指向常量的指针----指针指 ...

  6. open/fopen read/fread write/fwrite区别

    fopen /open区别 UNIX环境下的C 对二进制流文件的读写有两套班子:1) fopen,fread,fwrite ; 2) open, read, write这里简单的介绍一下他们的区别.1 ...

  7. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  8. esp和ebp详解

    最近在研究栈帧的结构,但总是有点乱,所以写了一个小程序来看看esp和ebp在栈帧中的作用.这个程序如下: 这个程序很简单,就是求两个数的值,然后输出即可.所以首先把它用gcc编译链接成a.out,进入 ...

  9. hdu 4715 Difference Between Primes

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...

  10. Java日期处理类的lenient属性

    这个特性很坑爹:@Test public void test() throws ParseException { SimpleDateFormat df = new SimpleDateFormat( ...