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

题意:一个n*m的玉米田,为1的是不可种植地带,为0才可以种植,有一个约束条件,就是相邻的不能同时种植,现在要你求有多少种植方式

思路:状压一般我们要去关注他的数据范围,因为与二进制有关,所以一般范围都会在32以内,然后我们首先向一行内满足状态的有多少个
这时候就必须熟悉位运算操作,我们把一行当作一个二进制,判断相邻即 x&(x<<1) 这是一行内满足要求的个数
但是这个我们还没有考虑图中的不可种植地带,这个时候我们就必须把这些状态去与图所比较,看是否满足要求,但是我们判断是够冲突,一般
只能去考虑二进制1是否有冲突,所以我把原图的0和1颠倒
已经把行冲突的考虑完了,现在考虑列冲突,因为我们同列相邻的为1也会发生冲突,所以我们把最新的一行的状态与前一行比较
dp[i][j]代表前i行中第i行放第j中状态满足要求的个数
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#define maxn 20
#define mod 1000000000
using namespace std;
typedef long long ll;
ll n,m;
ll dp[maxn][];
ll a[maxn];
ll top;
ll prime[];
ll num;
ll ok(ll x)//判断相邻是否满足要求
{
if(x&(x<<)) return ;
return ;
}
void init()//预处理出一行内所有满足要求的状态
{
top=<<m;
for(int i=;i<top;i++)
{
if(ok(i))
prime[num++]=i;
}
}
int fit(ll x,ll z) //判断第x行与z状态是否有冲突,即判断行内满足不相邻的状态是否与图有冲突
{
if(a[x]&z) return ;
return ;
}
int main()
{ cin>>n>>m;
init();
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
ll x;
cin>>x;
if(x==)//因为要用来判断会不会与图发生冲突,改成二进制1为不能放
a[i]+=<<(m-j);
}
}
for(int i=;i<num;i++)//看所有的状态是否满足第一行要求
{
if(fit(,prime[i])) dp[][i]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<num;j++)
{
if(!fit(i,prime[j])) continue;
for(int k=;k<num;k++)
{
if(prime[j]&prime[k]) continue;
dp[i][j]=(dp[i][j]+dp[i-][k])%mod;
}
}
}
ll sum=;
for(int i=;i<num;i++)
{
sum=(sum+dp[n][i])%mod;
}
cout<<sum;
}
 

最新文章

  1. 用php生成一个excel文件(原理)
  2. ES6 - Note3:数组、对象与函数的扩展
  3. CodeIgniter2.2.0-在控制器里调用load失败报错的问题
  4. 谈谈JavaScript类型检测
  5. oracle唯一索引与普通索引的区别和联系以及using index用法
  6. iOS 在制作framework时候对aggregate的配置
  7. gotoTop返回顶部 JS
  8. yii2 生成PDF格式的文件
  9. BZOJ 2292 永远挑战
  10. Gerrit清单库配置(转载)
  11. mysql约束(自己原先总结的有点不准)
  12. java多线程总结四:volatile、synchronized示例
  13. GET异步 请求图片步骤
  14. poj3062---输入什么输出什么
  15. 专访雷水果国:离1.5K至18K 一个程序猿5每年的成长之路
  16. 专业MySQL数据库管理专家SQL Manager for MySQL发布5.4版本
  17. C#的Task和Java的Future
  18. SDCycleScrollView 添加初始滚动页码
  19. Java Web(十三) 使用javamail进行发送邮件,(使用QQ,163,新浪邮箱服务器)
  20. React 和 Angular 各有什么优缺点,各自又适合什么开发场景?

热门文章

  1. 1*1的卷积核与Inception
  2. HttpRunner 接口自动化简单实践
  3. Hadoop -- 概念
  4. flask_mail发送163邮件,报553错误的原因
  5. &lt;转&gt;jmeter(二十一)jmeter常用插件介绍
  6. GitHub linux 提交文件及403错误处理
  7. 2、Kafka架构
  8. 王之泰201771010131《面向对象程序设计(java)》第九周学习总结
  9. vivado 创建PS工程
  10. 函数func_get_args详解