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.

Source

之前做了一下“铺地砖”的题,然后看别人用插头DP做,代码很简洁,于是也打算学习一下插头DP。

这个题应该是比较基础,反正1A了,爽歪歪。

不过第一次写的可能有些丑。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
const int Mod=;
int dp[][<<],ans,a[][],m,n;
bool check(int u,int x,int y)
{
for(int i=;i<=m;i++) if((x&(<<(i-)))&&(x&(<<(i-)))) return false;
for(int i=;i<=m;i++) if((y&(<<(i-)))&&(y&(<<(i-)))) return false;
for(int i=;i<=m;i++) if(!a[u-][i]&&(x&(<<(i-)))) return false;
for(int i=;i<=m;i++) if(!a[u][i]&&(y&(<<(i-)))) return false;
for(int i=;i<=m;i++) if((x&(<<(i-)))&&(y&(<<(i-)))) return false;
return true;
}
int main()
{
int i,j,k;
while(~scanf("%d%d",&n,&m)){
for(i=;i<=n;i++)
for(j=m;j>=;j--)
scanf("%d",&a[i][j]);
dp[][]=;
for(i=;i<=n;i++){
for(j=;j<<<m;j++)
for(k=;k<<<m;k++)
if(check(i,j,k))
dp[i][k]=(dp[i][k]+dp[i-][j])%Mod;
}
for(i=;i<<<m;i++) ans=(ans+dp[n][i])%Mod;
printf("%d\n",ans);
}
return ;
}

最新文章

  1. HTML5+JS 《五子飞》游戏实现(七)游戏试玩
  2. centos 7.0 查看根目录下所有文件夹
  3. 在64位windows下使用instsrv.exe和srvany.exe创建windows服务
  4. Uva 116,单向TSP
  5. [原创]SSIS-执行包任务调用子包且子包读取父包变量
  6. VersionCode和VersionName
  7. AVR单片机RC触摸
  8. DNS,ARP,RARP,NAT,WINS的作用和区别
  9. VS2010,原来还有这些快捷键,果断记下来!
  10. 微信小程序开源项目库集合
  11. CSS3 Columns:比table更好用的分列式布局方法
  12. PO/VO/POJO/BO/VO图解
  13. Ionic 安装创建项目
  14. Duplicate entry &#39;97112&#39; for key 1
  15. Web地图呈现原理
  16. TCP 总结
  17. slf4j的使用2
  18. Vue组件间传值 v-model
  19. [20180927]ora-01426.txt
  20. 基于tensorflow的逻辑分类

热门文章

  1. C#字符串内插-$
  2. 2-0 虚拟机与Linux系统安装
  3. 如何为根分区扩容(centos7为例)
  4. mysql——修改表名、修改字段名、修改字段数据类型、增加字段、删除字段、修改字段排列位置、修改存储引擎、删除表 (示例)
  5. 多标签分类(multi-label classification)综述
  6. [c++] WINAPI
  7. Struts 2访问Servlet API
  8. python基础之 线程_进程关系
  9. 关于__name__==&#39;__main__&#39;的理解
  10. Android新版xUtils3工具类相关debug