Corn Fields
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6081   Accepted: 3226

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.

 
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define mod 100000000
int a[],dp[][<<];
bool check(int x,int y)
{
int z=x|y;
if(z>y)return ;
else return ;
}
bool check2(int x)
{
int z=x&;
x>>=;
while(x)
{
if(z&(x&))return ;
z=x&;
x>>=;
}
return ;
}
bool check1(int x,int y)
{
if(x&y)return ;
else return ;
}
int main()
{
int m,n,i,j,x,k;
cin>>m>>n;
for(i=; i<m; i++)
{
x=,a[i]=;
for(j=; j<n; j++)
{
scanf("%d",&x);
a[i]=(a[i]<<)+x;
}
}
memset(dp,,sizeof(dp));
for(j=; j<(<<n); j++)
if(check(j,a[])&&check2(j))
dp[][j]=;
for(i=; i<m; i++)
{
for(j=; j<(<<n); j++)
{
if(check(j,a[i])&&check2(j))
{
for(k=; k<(<<n); k++)
{
if(check1(k,j))
dp[i][j]+=dp[i-][k],dp[i][j]%=mod;
}
}
}
}
int sum=;
for(i=;i<(<<n);i++)sum+=dp[m-][i],sum%=mod;
cout<<sum<<endl;
}

Corn Fields poj3254(状态压缩DP)的更多相关文章

  1. Corn Fields——POJ3254状态压缩Dp

    Corn Fields Time Limit: 2000MS Memory Limit: 65536K Description Farmer John has purchased a lush new ...

  2. 洛谷P1879 [USACO06NOV]玉米田Corn Fields (状态压缩DP)

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

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

    题目大意:给出一个M*N的矩阵,元素为0表示这个地方不能种玉米,为1表示这个地方能种玉米,现在规定所种的玉米不能相邻,即每行或者没列不能有相邻的玉米,问一共有多少种种植方法. 举个例子: 2 3 1 ...

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

    题目大意:一个矩形的草地,分为多个格子,有的格子可以有奶牛(标为1),有的格子不可以放置奶牛(标为0),计算摆放奶牛的方案数. 分析: f[i,j]表示第i行状态为j的方案总数. 状态转移方程f[i, ...

  5. poj3254 Corn Fields 利用状态压缩求方案数;

    Corn Fields 2015-11-25 13:42:33 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10658   ...

  6. poj - 3254 - Corn Fields (状态压缩)

    poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...

  7. poj3254 状态压缩dp

    题意:给出一个n行m列的草地,1表示肥沃,0表示贫瘠,现在要把一些牛放在肥沃的草地上,但是要求所有牛不能相邻,问你有多少种放法.     分析:假如我们知道第 i-1 行的所有的可以放的情况,那么对于 ...

  8. POJ 3254 Corn Fields(状态压缩)

    一道状态压缩的题,错了好多次....应该先把满足的情况预处理出来 #include<iostream> #include<cstdio> #include<cstring ...

  9. POJ3254 - Corn Fields(状态压缩DP)

    题目大意 给定一个N*M大小的土地,土地有肥沃和贫瘠之分(每个单位土地用0,1来表示贫瘠和肥沃),要求你在肥沃的单位土地上种玉米,如果在某个单位土地上种了玉米,那么与它相邻的四个单位土地是不允许种玉米 ...

随机推荐

  1. 国内5家云服务厂商 HTTPS 安全性测试横向对比

    随着 Chrome.Firefox 等浏览器对 HTTPS 的重视,国内众多云服务厂商都相继提供 SSL 证书申购服务,但是大家有没有注意到一个细节,不同厂家申请的 SSL 证书,由于证书性能.功能差 ...

  2. windows server 2012 + sql server 2008 r2安装

    windows server 2012 r2  里面安装 sql server 2008 r2 问题总结 前提是 windows server 2012 r2 已经安装完成  ,(仅仅是安装完成 啥服 ...

  3. 使用Spring实现读写分离( MySQL实现主从复制)

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt403 1.  背景 我们一般应用对数据库而言都是"读多写少&quo ...

  4. 32位汇编第二讲,编写窗口程序,加载资源,响应消息,以及调用C库函数

    32位汇编第二讲,编写窗口程序,加载资源,响应消息,以及调用C库函数 (如果想看所有代码,请下载课堂资料,里面有所有代码,这里会讲解怎么生成一个窗口程序) 一丶32位汇编编写Windows窗口程序 首 ...

  5. 再起航,我的学习笔记之JavaScript设计模式20(策略模式)

    策略模式 策略模式(Strategy):将定义的一组算法封装起来,使其相互之间可以替换.封装的算法具有一定的独立性,不会随客户端变化而变化. 其实策略模式在我们生活中可应用的地方还是比较多的,比如在商 ...

  6. UCOS-II学习记录

    本文主要记录使用UCOS II的相关内容.包括如何完成第一个UCOS II应用程序,和如何创建任务,如何获取系统时间,和利用i3086 驱动完成时间获取,屏幕显示,按键驱动,信号量等内容. UCOS- ...

  7. Alpha 版本测试和发布说明

    Alpha版本测试报告 一bug汇总 做题时答案是错的.(已修复) 每次生成的题目一样(已经修复) 计时没有显示即倒计时,难度不同的功能没有实现(打算修复) 没有导入试卷和错题功能(不打算修复) 二. ...

  8. 201521123086 《Java程序设计》第8周学习总结

    本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 书面作业 1.List中指定元素的删除 题集jmu-Java-05-集合之4-1 1.1 实验总结 Answer: ...

  9. 201521123005 《java程序设计》 第七周学习总结

    1. 本周学习总结 参考资料: XMind 2. 书面作业 Q1ArrayList代码分析 1.1 解释ArrayList的contains源代码 ArrayList的contains源代码 /** ...

  10. 201521123012 《Java程序设计》第三周学习总结

    一.本章学习总结 1.面对对象:(1)类 <1>属性 [1]外部类 [2]内部类 <2>方法 [1]j静态 [2]非静态 (2)对象 <1>创建对象 <2&g ...