题目描述

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.

农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地。John打算在牧场上的某几格里种上美味的草,供他的奶牛们享用。

遗憾的是,有些土地相当贫瘠,不能用来种草。并且,奶牛们喜欢独占一块草地的感觉,于是John不会选择两块相邻的土地,也就是说,没有哪两块草地有公共边。

John想知道,如果不考虑草地的总块数,那么,一共有多少种种植方案可供他选择?(当然,把新牧场完全荒废也是一种方案)

输入输出格式

输入格式:

第一行:两个整数M和N,用空格隔开。

第2到第M+1行:每行包含N个用空格隔开的整数,描述了每块土地的状态。第i+1行描述了第i行的土地,所有整数均为0或1,是1的话,表示这块土地足够肥沃,0则表示这块土地不适合种草。

输出格式:

一个整数,即牧场分配总方案数除以100,000,000的余数。

输入输出样例

输入样例#1: 复制

2 3
1 1 1
0 1 0
输出样例#1: 复制

9
i
装压dp,1A,爽,dp[i][j]表示选取到地i行,上一行的状态是j
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
#define mod 100000000
inline int read() {
int x=,f=;
char c=getchar();
while(c<''||c>'') {
if(c=='-') f=-;
c=getchar();
}
while(c<=''&&c>='') {
x=x*+c-'';
c=getchar();
}
return x;
}
#define maxn 14
int map[maxn][maxn];
int b[maxn];
int no[maxn],dp[][<<];
int main() {
n=read(),m=read();
for(int i=;i<n;++i) {
for(int x,j=;j<m;++j) {
x=read();
if(x)b[i]|=(<<(j));
}
}
int num=(<<m);
for(int i=;i<num;++i)if(((b[]&i)==i)&&(!(i&(i>>))&&!(i&i<<)))dp[][i]=;
for(int i=;i<n;++i) {
for(int j=;j<num;++j) {
if(((b[i]&j)==j)&&(!(j&(j>>))&&!(j&j<<))) {
for(int k=;k<num;++k){
if(!(j&k)) {
dp[i][j]=(dp[i][j]+dp[i-][k])%mod;
}
}
}
}
}
int ans=;
for(int i=;i<num;++i) {
ans=(ans+dp[n-][i])%mod;
}
printf("%d\n",ans);
return ;
}

luogu P1879 [USACO06NOV]玉米田Corn Fields的更多相关文章

  1. 【luogu P1879 [USACO06NOV]玉米田Corn Fields】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1879 状压DP. 设dp[i][j]表示第i行,状态为j的方案数 初始dp[0][0] = 1 这样一共12 ...

  2. P1879 [USACO06NOV]玉米田Corn Fields(状压dp)

    P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...

  3. C++ 洛谷 P1879 [USACO06NOV]玉米田Corn Fields

    没学状压DP的看一下 合法布阵问题  P1879 [USACO06NOV]玉米田Corn Fields 题意:给出一个n行m列的草地(n,m<=12),1表示肥沃,0表示贫瘠,现在要把一些牛放在 ...

  4. 洛谷 P1879 [USACO06NOV]玉米田Corn Fields 题解

    P1879 [USACO06NOV]玉米田Corn Fields 题目描述 Farmer John has purchased a lush new rectangular pasture compo ...

  5. 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)

    洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...

  6. P1879 [USACO06NOV]玉米田Corn Fields (状压dp入门)

    题目链接: https://www.luogu.org/problemnew/show/P1879 具体思路: 我们可以先把所有合法的情况枚举出来,然后对第一行判断有多少种情况满足,然后对于剩下的行数 ...

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

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

  8. P1879 [USACO06NOV]玉米田Corn Fields

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

  9. 洛谷P1879 [USACO06NOV]玉米田Corn Fields【状压DP】题解+AC代码

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

随机推荐

  1. 某比赛小记1- 挑选第N大数字

    题目:给1000个数字(有重复),从小到大排列后,挑选第N个数字. 数字文件如下:numbers.rar ,挑选第727个数字. java版本: //数组初始化 String str = " ...

  2. 为Anaconda添加新的源

    为Anaconda添加新的源 在cmd中输入以下内容即可, 清华的源,速度非常快 conda config --add channels https://mirrors.tuna.tsinghua.e ...

  3. 理解 PHP output buffer

    在需要使用输出缓存区的时候,一般会在代码中加上ob_start()这个函数. 这是因为php.ini中output_buffering设置为off时,则缓存区处于关闭状态,需要用ob_start()打 ...

  4. URAL 1033 Labyrinth

    E - Labyrinth Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submi ...

  5. hdu 5444 构建二叉树,搜索二叉树

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  6. 解决webstorm安装babel卡死问题

    2017.07.16 现在大家可以直接使用yarn的方式安装包,可以解决babel目录过长导致webstorm卡死的问题. yarn的安装不会执行组件命令就不会导致node_modules下面继续嵌套 ...

  7. activemq的安装启动

    Activemq安装和启动   官网:http://activemq.apache.org/   安装启动: $ tar -zxvf apache-activemq-5.11.1-bin.tar.gz ...

  8. JSON的使用_检查JSON工具

    json简单说就是javascript中的对象和数组. 1.对象:对象在js中表示为"{}"扩起来的内容,数据结构为 {key:value,key:value,...}的键值对的结 ...

  9. Welcome-to-Swift-10属性 (Properties)

    属性将值跟特定的类.结构或枚举关联.存储属性存储常量或变量作为实例的一部分,计算属性计算(而不是存储)一个值.计算属性可以用于类.结构体和枚举里,存储属性只能用于类和结构体. 存储属性和计算属性通常用 ...

  10. npm scripts设置环境变量方法

    windows set NODE_ENV=production "scripts": { "release": "set NODE_ENV=produ ...