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. jmeter ---json几种读取方式,ArrayList循环读取

    在之前写过提取json数据格式的文章,这次对jmeter读取json数据格式进行整理. 举例一个接口的response 格式如下: { "data" : { "devic ...

  2. C# 异步编程1 APM模式异步程序开发

    C#已有10多年历史,单从微软2年一版的更新进度来看活力异常旺盛,C#中的异步编程也经历了多个版本的演化,从今天起着手写一个系列博文,记录一下C#中的异步编程的发展历程.广告一下:喜欢我文章的朋友,请 ...

  3. 创建DNS子域及view

    author:JevonWei 版权声明:原创作品 子域 子域同父域在同一个服务器上 新建子域jevon.danran.com vim /etc/named.rfc1912.zones zone &q ...

  4. node简单配置一台服务器

    要想使用nodeJS来搭建服务器,首先需要一个必备的条件:node必须安装,建议为4.0版本及以上: 在node中,为我们封装了好多类,搭建服务器需要的一个类是"http"类. 用 ...

  5. URL.createObjectURL() 与 URL.revokeObjectURL()

    .URL.createObjectURL URL.createObjectURL()方法会根据传入的参数创建一个指向该参数对象的URL. 这个URL的生命仅存在于它被创建的这个文档里. 新的对象URL ...

  6. 定宽块状元素居中 1记(text-align/margin:0 auto)

    对于text-align:center的用法只是针对文本相对于父元素的居中,例如: #jz2{ width:300px; margin: 10px auto; border:2px solid red ...

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

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

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

    1. 本周学习总结 2. 书面作业 clone方法1.1 Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么?                 ...

  9. 201521123077 《Java程序设计》第14周学习总结

    1. 本周学习总结 1.1以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 1. MySQL数据库基本操作 -参考:实验任务书-题目1 建立数据库,将自己的姓名.学号作为一条 ...

  10. 201521123032 《Java程序设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...