题目链接:http://poj.org/problem?id=3254

Time Limit: 2000MS Memory Limit: 65536K

Description

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.

Input

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)

Output

Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.

Sample Input

2 3
1 1 1
0 1 0

Sample Output

9

Hint

Number the squares as follows:

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.

题解:

怎么说呢,类似的状压DP题解写多了真的挺无聊的,如果你已经撸完了:

http://www.cnblogs.com/dilthey/p/7623028.html

http://www.cnblogs.com/dilthey/p/7604432.html

这两道题目的话,再来看本题,真的是很水的,所以就懒得写题解了,反正就是差不多的思路;

AC代码:

 #include<cstdio>
#include<cstring>
int m,n,mp[];
int dp[][<<];
int main()
{
while(scanf("%d%d",&m,&n)!=EOF)//m行n列
{
for(int i=,tmp;i<=m;i++)
{
mp[i]=;
for(int j=;j<=n;j++)
{
scanf("%d",&tmp);
tmp=!tmp;
mp[i]|=tmp;
if(j!=n) mp[i]<<=;
}
} memset(dp,,sizeof(dp));
for(int i=;i<(<<n);i++)//初始化第一行
{
if( i&(i<<) || i&mp[] ) continue;
dp[][i]=;
}
for(int r=;r<=m;r++)//遍历第2~m行
{
for(int i=;i<(<<n);i++)//枚举第r行状态
{
if( i&(i<<) || i&mp[r] ) continue;
for(int j=;j<(<<n);j++)//枚举第r-1行状态
{
if( j&(j<<) || j&mp[r-] || i&j ) continue;
dp[r][i]+=dp[r-][j];
}
}
} int ans=;
for(int i=;i<(<<n);i++)
{
if( i&(i<<) || i&mp[m] ) continue;
ans+=dp[m][i];
}
printf("%d\n",ans%);
}
}

PS.哦对,有一点倒是值得提醒,需要对100000000取模,因为忘记了这个WA了一发,羞愧脸。

POJ 3254 - Corn Fields - [状压DP水题]的更多相关文章

  1. POJ 3254 Corn Fields (状压dp)

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

  2. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  3. Poj - 3254 Corn Fields (状压DP)(入门)

    题目链接:https://vjudge.net/contest/224636#problem/G 转载于:https://blog.csdn.net/harrypoirot/article/detai ...

  4. poj 3254 Corn Fields 状压dp入门

    题目链接 题意 在\(M\times N\)的\(0,1\)格子上放东西,只有标记为\(1\)的格子可以放东西,且相邻的格子不能同时放东西.问有多少种放法. 思路 参考:swallowblank. \ ...

  5. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  6. POJ 3254 Corn Fields (状压入门)

    Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M≤ 12; 1 ≤ N ≤ 12) ...

  7. 【POJ3254】Corn Fields 状压DP第一次

    !!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...

  8. P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp

    正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...

  9. [USACO06NOV]玉米田Corn Fields 状压DP

    题面: 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上美味的草,供他的 ...

随机推荐

  1. Android内存泄漏检測与MAT使用

    公司相关项目须要进行内存优化.所以整理了一些分析内存泄漏的知识以及工作分析过程. 本文中不会刻意的编写一个内存泄漏的程序,然后利用工具去分析它.而是通过介绍相关概念,来分析怎样寻找内存泄漏.并附上自己 ...

  2. 02-centOS6.7安装

    CentOS6.5在VMware10中安装 1.启动VMware的画面 2.点击File--->New Virtual Machine 创建一台新虚拟机 3.在弹出框中选择典型安装 4.选择I ...

  3. hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configured filemask: output.xml

    错误描述: hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configu ...

  4. 使用 Splash

    Splash 简介与安装 Splash Lua 脚本 Splash 对象属性 Splash 对象方法 Splash API 调用 Splash 负载均衡

  5. [Python] First-class Everything (Python缔造者Guido van Rossum关于bound/unbound method的来历叙述)

    First-class Everything -- Guido van Rossum First-class object: 第一类对象.意指可在执行期创建并作为参数传递给其他函数或存入一个变量的对象 ...

  6. Java中过滤器和拦截器的区别

    1.拦截器是基于java反射机制的,而过滤器是基于函数回调的. 2.过滤器依赖于servlet容器,而拦截器不依赖于servlet容器. 3.拦截器只对action起作用,而过滤器几乎可以对所有请求起 ...

  7. 《转载》Eclipse项目上传码云

    本文转载自http://blog.csdn.net/izzyliao/article/details/53074452 把Eclipse项目上传到码云的步骤: 1.登录码云:新建项目 2.输入项目名: ...

  8. 【转载】.NET 开发者必备的工具箱

    本文作者Spencer是一名专注于ASP.NET和C#的程序员,他列举了平时工作.在家所使用的大部分开发工具,其中大部分工具都是集中于开发,当然也有一些其它用途的,比如图片处理.文件压缩等. 如果你是 ...

  9. 【转载】6种.net分布式缓存解决方案

    . 使用内置ASP.NET Cache (System.Web.Caching) : https://msdn.microsoft.com/en-us/library/system.web.cachi ...

  10. Linux下grep命令查找带有tab(退格)的字符

    需要在日志文件统计删除的主帖,而日志文件是tab(退格)字符隔开的:假设日志文件名叫delete.log. 保存格式和保存的数据如下, 删除日期            帖子类型(11为主帖,12为回帖 ...