意甲冠军:

要在m行n陆行,有一些格您可以种树,别人做不到的。不相邻的树,我问了一些不同的共同拥有的法律。

分析:

从后往前种,子问题向父问题扩展,当种到某一格时仅仅有他和他后面的n-1个格子的情况对它有影响。故对这n个格子进行编码为状态S,表示种完(多米诺骨牌那题是放置前。注意差别,都可行)这n个格子的状态。父问题由稍小子问题逐步解决,正是动态规划的思想。

代码:

//poj 3254
//sep9
#include <iostream>
using namespace std;
const int maxN=14;
const int mod=100000000;
int land[maxN][maxN];
int dp[2][1<<maxN];
int m,n; int main()
{
scanf("%d%d",&m,&n);
int i,j,used;
for(i=0;i<m;++i)
for(j=0;j<n;++j)
scanf("%d",&land[i][j]);
int *cur=dp[0],*nxt=dp[1];
cur[0]=1;
for(i=m-1;i>=0;--i)
for(j=n-1;j>=0;--j){
for(used=0;used<1<<n;++used){
if(land[i][j]==0){
if(used>>j&1)
nxt[used]=0;
else{
nxt[used]=cur[used];
nxt[used]+=cur[used|(1<<j)];
nxt[used]%=mod;
}
}
else{
int res=0;
if((used>>j&1)&&(used>>(j+1)&1)){
res=0;
}else if(!(used>>j&1)&&(used>>(j+1)&1)){
res=cur[used];
res+=cur[used|(1<<j)];
}else if((used>>j&1)&&!(used>>(j+1)&1)){
res=cur[used&(~(1<<j))];
}else if(!(used>>j&1)&&!(used>>(j+1)&1)){
res=cur[used];
res+=cur[used|(1<<j)];
}
nxt[used]=res%mod;
}
}
swap(cur,nxt);
}
int sum=0;
for(int i=0;i<1<<n;++i){
sum+=cur[i];
sum%=mod;
}
printf("%d",sum);
return 0;
}

poj 3254 Corn Fields 国家压缩dp的更多相关文章

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

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

  2. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  3. POJ 3254 Corn Fields (状态压缩DP)

    题意:在由方格组成的矩形里面种草,相邻方格不能都种草,有障碍的地方不能种草,问有多少种种草方案(不种也算一种方案). 分析:方格边长范围只有12,用状态压缩dp好解决. 预处理:每一行的障碍用一个状态 ...

  4. POJ 3254 Corn Fields 状态压缩DP (C++/Java)

    id=3254">http://poj.org/problem? id=3254 题目大意: 一个农民有n行m列的地方,每一个格子用1代表能够种草地,而0不能够.放牛仅仅能在有草地的. ...

  5. poj - 3254 Corn Fields (状态压缩dp入门)

    http://poj.org/problem?id=3254 参考:http://blog.csdn.net/accry/article/details/6607703 农夫想在m*n的土地上种玉米, ...

  6. POJ 3254 Corn Fields状态压缩DP

    下面有别人的题解报告,并且不止这一个状态压缩题的哦···· http://blog.csdn.net/accry/article/details/6607703 下面是我的代码,代码很挫,绝对有很大的 ...

  7. [ACM] POJ 3254 Corn Fields(状态压缩)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8062   Accepted: 4295 Descr ...

  8. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  9. POJ 3254 Corn Fields (状压dp)

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

随机推荐

  1. APK 代码混淆

    # To enable ProGuard in your project, edit project.properties # to define the proguard.config proper ...

  2. 移动web:翻页场景动画

    在移动web,特别是在微信中,经常看到一种翻页动画效果,也称为场景动画. 一页一页的翻过,像在看书,每页的内容以各种"炫酷"的效果出现在你的眼里,配上一首动听的音乐,你有没有喜欢上 ...

  3. RESTful API Design With NodeJS & Restify

    http://code.tutsplus.com/tutorials/restful-api-design-with-nodejs-restify--cms-22637 The RESTful API ...

  4. 使用android SpannableStringBuilder实现图文混排,看到许多其他

    项目开发需要达到这种效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZmFuY3lsb3ZlamF2YQ==/font/5a6L5L2T/fontsiz ...

  5. 如何在 Swift 中优雅地处理 JSON

    阅读目录 在Swift中使用JSON的问题 开始 基础用法 枚举(Enumeration) 下标(Subscripts) 打印 调试与错误处理 后记   因为Swift对于类型有非常严格的控制,它在处 ...

  6. Visual Studio 2012中使用Zen Coding,写html的神器!

    点工具 -扩展和更新的联机库中 找到以下俩插件 安装后重新启动 新建一个html文件.将下行代码拷贝到页面里. div>(header>div)+(section>ul>li. ...

  7. Red Hat Enterprise Linux Server(RHEL) yum安装软件时This system is not registered with RHN. RHN support will be disabled. 的解决方法(转)

    新安装了redhat6.5.安装后,登录系统,使用yum update 更新系统.提示: This system is not registered to Red Hat Subscription M ...

  8. HDU - 5036 Operation the Sequence

    Problem Description You have an array consisting of n integers: a1=1,a2=2,a3=3,-,an=n. Then give you ...

  9. therefore/so/hence/then/accordingly/Thus

    这几个词的区别大致可从以下几方面去看:1.therefore adv.因此, 所以=for that reason=consequently常用于连接两个并列分句,其前加“and”或分号“:”.He ...

  10. STL--F - Sequence(n*m-&gt;之前的最低要求m个月)

    F - Sequence Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...