Corn Fields 状压动归入门题
#include<cstdio>
using namespace std;
const int N=15;
int dp[N][1<<N],v[1<<N],M[N][N];
int n,m,cnt;
const int mod=100000000;
void init()
{
for(int i=0;i<(1<<m);++i)
if((i&(i<<1))==0)v[++cnt]=i;
}
int ok(int dep,int cur){
for(int i=1;i<=m;++i)
if((cur&(1<<(i-1)))&&!M[dep][m-i+1])return 0;
return 1;
}
int main(){
//freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
init();
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)scanf("%d",&M[i][j]);
for(int i=1;i<=n;++i)
{
for(int j=1;j<=cnt;++j)
{
if(!ok(i,v[j]))continue;
if(i==1){
dp[i][j]=1;continue;
}
for(int k=1;k<=cnt;++k)
if((v[k]&v[j])==0){
dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;
}
}
}
int ans=0;
for(int i=1;i<=cnt;++i)
ans=(ans+dp[n][i])%mod;
printf("%d",ans);
return 0;
}
Corn Fields 状压动归入门题的更多相关文章
- Poj - 3254 Corn Fields (状压DP)(入门)
题目链接:https://vjudge.net/contest/224636#problem/G 转载于:https://blog.csdn.net/harrypoirot/article/detai ...
- POJ 3254 Corn Fields (状压入门)
Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M≤ 12; 1 ≤ N ≤ 12) ...
- POJ 3254 - Corn Fields - [状压DP水题]
题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...
- POJ 3254 Corn Fields (状压dp)
题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...
- POJ 1684 Corn Fields(状压dp)
描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...
- 【POJ3254】Corn Fields 状压DP第一次
!!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...
- [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp
题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...
- P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp
正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...
- [USACO06NOV]玉米田Corn Fields 状压DP
题面: 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上美味的草,供他的 ...
随机推荐
- Mahmoud and a Dictionary
Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- Basic Memory Structures
Basic Memory Structures The basic memory structures associated with Oracle Database include: System ...
- JavaScript向window onload添加加载函数
有时候我们需要在页面加载事件后完成一些函数操作,对于函数比较多的情况下可以写一个统一的加载函数 .本函数来自于JavaScript DOM 编程艺术: function addLoadEvent(fu ...
- 【ACM】hdu_1170_Balloon Comes!_201307261946
Balloon Comes!Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [bzoj1606][Usaco2008 Dec]Hay For Sale 购买干草_动态规划_背包dp
Hay For Sale 购买干草 bzoj-1606 Usaco-2008 Dec 题目大意:约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单 ...
- redis之Hash存储与String存储内存消耗对照
存储对象User String存储方式: SET media:1155315 939 GET media:1155315 > 939 String结构存储该对象 User243 243600 存 ...
- 【cl】cmd相关命令
cd 进入目录 dir 列出当前目录下的文件[在linux上是ls] e: 进入E盘 tab键可以快速进入目录
- 问题1-The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
问题一:The type java.lang.String cannot be resolved. It is indirectly referenced from required .class f ...
- 能够替代浮动的inline-block
浮动有个缺点:脱离了原来的文档流,导致父容器无高度.使用inline-block不会脱离文档流.且无忘记清空浮动的困扰 并排的div都设置position:inline-block,vertical- ...
- 《转》Ceilometer Alarm API 參数具体解释 及 举例说明
Ceilometer Alarm是H版新加入的功能,监控报警是云平台必不可少的部分,Ceilometer已经实现了比較完好的监控体系.报警怎么能缺少呢?用过AWS CloudWatch Alarm的人 ...