POJ 1684 Corn Fields(状压dp)
描述
Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.
Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.
输入
Line 1: Two space-separated integers: M and N
Lines 2..M+1: Line i+1 describes row i of the pasture with N space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)
输出
Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.
样例输入
2 3
1 1 1
0 1 0
样例输出
9
提示
1 2 3
4
There are four ways to plant only on one squares (1, 2, 3, or 4), three ways to plant on two squares (13, 14, or 34), 1 way to plant on three squares (134), and one way to plant on no squares. 4+3+1+1=9.
#include<stdio.h>
#include<string.h>
using namespace std; const int mod=1e9; int dp[][],state[],cur[];
int n,m,k,tot;
int main()
{
while(scanf("%d%d",&m,&n)!=EOF)
{
tot=;
for(int i=;i<(<<n);i++)///列的所有可行状态
if(!(i&(i<<)))///没有连续两个1
state[++tot]=i; for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
{
scanf("%d",&k);
if(!k)cur[i]+=<<(n-j);///第i行不可行置1,用于判断不可行状态
} for(int i=;i<=tot;i++)
if(!(state[i]&cur[]))
dp[][i]=;
for(int i=;i<=m;i++)
{
for(int j=;j<=tot;j++)///枚举当前状态
{
if(state[j]&cur[i])continue;///当前状态不可行
for(int k=;k<=tot;k++)///枚举前一个状态
{
if(state[k]&cur[i-])continue;///当前前一状态不可行
if(state[j]&state[k])continue;///当前状态和前一状态不可行
dp[i][j]=(dp[i][j]+dp[i-][k])%mod;///当前状态可以从前一状态的K状态转移过来
}
}
}
int ans=;
for(int i=;i<=tot;i++)
ans=(ans+dp[m][i])%mod;
printf("%d\n",ans);
}
return ;
}
POJ 1684 Corn Fields(状压dp)的更多相关文章
- 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入门题,将可以种菜的状态用一个数的二进制表 ...
- [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp
题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...
- Poj - 3254 Corn Fields (状压DP)(入门)
题目链接:https://vjudge.net/contest/224636#problem/G 转载于:https://blog.csdn.net/harrypoirot/article/detai ...
- poj 3254 Corn Fields 状压dp入门
题目链接 题意 在\(M\times N\)的\(0,1\)格子上放东西,只有标记为\(1\)的格子可以放东西,且相邻的格子不能同时放东西.问有多少种放法. 思路 参考:swallowblank. \ ...
- 【POJ3254】Corn Fields 状压DP第一次
!!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...
- P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp
正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...
- [USACO06NOV]玉米田Corn Fields 状压DP
题面: 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上美味的草,供他的 ...
- [USACO06NOV]玉米田Corn Fields (状压$dp$)
题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 块草皮,且最后一位状态为 \(k\) . 同时多记录一个每一列中的 ...
随机推荐
- 18_使用react脚手架构建应用
一.什么是脚手架 1.脚手架:用来帮助程序员快速创建一个基于xxx项目的模板仓库(可以理解为网上的大神写好了基础模板直接下载无需自己配置) 1)包含了所有需要的配置 2)指定好了所有依赖 3)可以直接 ...
- css- 范围选择
1.子元素范围选择 举例 .iconList_wr li:nth-child(n + 1):nth-child(-n + 4) { margin-right: 0.6rem; } .iconList_ ...
- springboot 项目 注意事项
SpringBoot出现下列错误. Your ApplicationContext is unlikely to start due to a @ComponentScan of the defaul ...
- Oracle数据库中的数据出错的解决办法
http://www.jcwcn.com/article/database/oracle/ 今天上班犯了一个严重的错误:把我们系统所使用的Oracle数据库中的数据给改掉了!当发现自己改错时,顿时冒了 ...
- 【原创】锐捷实现OSPF路由协议和NAT地址转换协议
路由网络设计与实施 [锐捷设备实现OSPF路由协议与NAT地址转换] 说明: 本文是在多VLAN双星型交换网络的基础之上发展的.关于组建多VLAN双星型交换网络,请参阅: <思科和锐捷组建多 ...
- C++ 动态创建按钮及 按钮的消息响应
动态创建的按钮 都会在消息 OnCommand 中得到处理,无论是什么消息,都会处理的 1\创建按钮 CButton* btn = new CButton(); btn->Create(_T(, ...
- C++ AfxBeginThread的介绍/基本用法
AfxBeginThread 用户界面线程和工作者线程都是由AfxBeginThread创建的.现在,考察该函数:MFC提供了两个重载版的AfxBeginThread,一个用于用户界面线程,另一 ...
- css样式中的绝对路径的参考对象
如果div标签中没有position:absolute;样式,那么img的参考对象就是浏览器 如果div标签中有position:absolute;样式,那么img的参考对象就是父元素,即div标签
- 吴裕雄 oracle 管理数据表对象
- NBU 还原LINUX ORACLE RAC数据库(CRM)
CRM集群数据库恢复 linux centos 6.6 oracle 11.2.0.3 集群环境 1.53 oraclea 1.54 oracleb 在linux操作系统root用户下安装好NBUci ...