题目链接: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. Windows Server 2008 + SQL Server 2005集群

    一. 基础环境 1. 服务器规划 2. 网络拓扑 二. 相关说明 1.为了节约服务器资源,AD服务器可以和iSCSI设备服务器同为一台服务器.由于iSCSI软件需要,目前微软只开发了基于Windows ...

  2. 8 -- 深入使用Spring -- 7...4 使用自动装配

    8.7.4 使用自动装配 在自动装配策略下,Action还是由Spring插件创建,Spring 插件在创建Action实例时,利用Spring的自动装配策略,将对应的业务逻辑组件注入Action实例 ...

  3. 7 -- Spring的基本用法 -- 8... 抽象Bean与子Bean;Bean继承与Java继承的区别;容器中的工厂Bean;获得Bean本身的id;强制初始化Bean

    7.8 深入理解容器中的Bean 7.8.1 抽象Bean与子Bean 把多个<bean.../>配置中相同的信息提取出来,集中成配置模版------这个配置模版并不是真正的Bean,因此 ...

  4. 在SSH框架中,如何得到POST请求的URL和参数列表

    在做项目的API通知接口的时候,发现在SSH框架中无法获取到对方服务器发来的异步通知信息.最后排查到的原因可能是struts2对HttpServletRequest进行了二次处理,那么该如何拿到pos ...

  5. Jackson(ObjectMapper)的简单使用(可转xml)

    参考文章:http://www.cnblogs.com/hoojo/archive/2011/04/22/2024628.html  (原文章更详细哦,且有介绍xml与java对象的互转) 参考文章作 ...

  6. android新建的项目界面上没有显示怎么办?

    看log也没有说明具体情况? 一翻折腾在清单文件里加了权限就好了!!!

  7. java的两种冒泡算法

    所谓的冒泡算法,就是给数组进行排序,可以根据以小到大的顺序,也可以根据以小到大的顺序,在数组的封装类java.util.Arrays通过sort方法进行按升序的排序.那不用类的话怎么进行呢? 思路一: ...

  8. (转载)JVM实现synchronized的底层机制

    目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...

  9. 【PHP】常见算法

    1 冒泡排序 思路:在要排序的一组数中,对当前还未排好的序列,从前往后对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒. 即,每当两相邻的数比较后发现它们的排序与排序要求相反时,就将它 ...

  10. Delphi Code Editor 之 几个特性

    Delphi Code Editor有几个特性在编写大规模代码时非常有用.下面分别进行介绍: 1.Code Templates(代码模板) 使用代码模板可把任意预定义代码(或正文)插入到单元文件中.当 ...