poj 3254
状态压缩 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的更多相关文章
- poj 3254 状压dp入门题
1.poj 3254 Corn Fields 状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...
- 状压DP POJ 3254 Corn Fields
题目传送门 /* 状态压缩DP:先处理硬性条件即不能种植的,然后处理左右不相邻的, 接着就是相邻两行查询所有可行的种数并累加 写错一个地方差错N久:) 详细解释:http://www.tuicool. ...
- POJ 3254 Corn Fields(状压DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13732 Accepted: 7216 Desc ...
- poj 3254 Corn Fields 国家压缩dp
意甲冠军: 要在m行n陆行,有一些格您可以种树,别人做不到的.不相邻的树,我问了一些不同的共同拥有的法律. 分析: 从后往前种,子问题向父问题扩展,当种到某一格时仅仅有他和他后面的n-1个格子的情况对 ...
- Corn Fields POJ - 3254 (状压dp)
题目链接: Corn Fields POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- poj - 3254 - Corn Fields (状态压缩)
poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- poj 3254 Corn Fields
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POJ 3254 Corn Fields (状压dp)
题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...
随机推荐
- ASP.NET MVC5学习笔记之Action参数模型绑定之模型元数据和元数据提供
一. 元数据描述类型ModelMetadata 模型元数据是对Model的描述信息,在ASP.NET MVC框架中有非常重要的作用,在模型绑定,模型验证,模型呈现等许多地方都有它的身影.描述Model ...
- Show or Hide Menu List via ng-show
<div ng-app ng-controller='MenuController'> <ul ng-show='menuState_show'> <li>Stun ...
- Mapreduce中的字符串编码
Mapreduce中的字符串编码 $$$ Shuffle的执行过程,需要经过多次比较排序.如果对每一个数据的比较都需要先反序列化,对性能影响极大. RawComparator的作用就不言而喻,能够直接 ...
- sqlalchemy - day2
Relationship Configuration 一.one to many 直接上代码 from sqlalchemy import create_engine engine = create ...
- Python学习教程(learning Python)--1.1Python程序设计流程
Python程序设计与其他高级语言程序设计流程基本一致 step1 程序设计 step2 编写Python代码 setp3 Python语句语法纠错 step4 测试程 ...
- 【WPF学习日记】——Window的DataContext绑定ViewModel
1.全局的ViewModel绑定: a)设定全局的ViewModel(App.xaml中): 1 <Application x:Class="MyTest.App" 2 xm ...
- db2建立表空间
--缓冲池 CREATE BUFFERPOOL EMP_BUF_POOL IMMEDIATE ALL DBPARTITIONNUMS SIZE 250 NUMBLOCKPAGES 0 PAG ...
- Should .close() be put in finally block or not?
The following are 3 different ways to close a output writer. The first one puts close() method in tr ...
- OSGi之Bundle
OSGi提出的根源是什么?在我看来就是对JVM的类加载机制进行了扩展,添加了一系列的规则,使得原有的类包(Class Package)扩展到类域(Class Domain).然后是建立在类域上的一系列 ...
- GoAhead 嵌入式web
https://embedthis.com/goahead/ 入手了一个360 4g wifi :使用jquery .goahead Goahead webserver编辑 GoAhead We ...