Corn Fields
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 16909 Accepted: 8939

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

[Submit]  
[Go Back]   [Status]  
[Discuss]





设f[i][s]表示第i行s状态下的方案数,则对于所有i - 1行与s不冲突的方案都可以转移

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define fo(i,x,y) for (int i = (x); i <= (y); i++)
#define Redge(u) for (int k = head[u]; k != -1; k = edge[k].next)
using namespace std;
const int maxn = 20,maxm = 1 << 12,INF = 1000000000,P = 100000000; inline int read(){
int out = 0,flag = 1;char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = out * 10 + c - 48; c = getchar();}
return out * flag;
} int f[maxn][maxm],N,M,le[maxm];
bool ill[maxm]; int main()
{
N = read();
M = read();
int maxv = (1 << M) - 1;
for (int i = 1; i <= N; i++){
for (int j = 1; j <= M; j++)
le[i] = (le[i] << 1) + read();
}
for (int s = 0; s <= maxv; s++){
bool sig = false; int t = s;
while (t){
if ((t & 1)&& sig) {ill[s] = true; break;}
else if (t & 1) sig = true;
else sig = false;
t >>= 1;
}
}
for (int s = 0; s <= maxv; s++){
if (!ill[s] && (s | le[1]) == le[1])
f[1][s] = 1;
}
for (int i = 2; i <= N; i++)
for (int e = 0; e <= maxv; e++){
if (ill[e] || (e | le[i]) != le[i]) continue;
for(int s = 0; s <= maxv; s++){
if (e & s) continue;
f[i][e] = (f[i][e] + f[i - 1][s]) % P;
}
}
int ans = 0;
for (int i = 0; i <= maxv; i++) ans = (ans + f[N][i]) % P;
cout<<ans<<endl;
return 0;
}

POJ P3254 Corn fields 【状压dp】的更多相关文章

  1. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  2. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  3. POJ 1684 Corn Fields(状压dp)

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

  4. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  5. Poj - 3254 Corn Fields (状压DP)(入门)

    题目链接:https://vjudge.net/contest/224636#problem/G 转载于:https://blog.csdn.net/harrypoirot/article/detai ...

  6. poj 3254 Corn Fields 状压dp入门

    题目链接 题意 在\(M\times N\)的\(0,1\)格子上放东西,只有标记为\(1\)的格子可以放东西,且相邻的格子不能同时放东西.问有多少种放法. 思路 参考:swallowblank. \ ...

  7. 【POJ3254】Corn Fields 状压DP第一次

    !!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostre ...

  8. P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp

    正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...

  9. [USACO06NOV]玉米田Corn Fields 状压DP

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

  10. [USACO06NOV]玉米田Corn Fields (状压$dp$)

    题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 块草皮,且最后一位状态为 \(k\) . 同时多记录一个每一列中的 ...

随机推荐

  1. C# VS,连接到oracle 报要升级到8.多少版本的错

    1:确定服务器的oracle版本 2:本地的客户端版本要和服务器一致 3:操作系统位数要一致

  2. Sqlite数据多表联合update

    其实在Mysql中,多表联合update不是什么难事. 语法: 1 UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ... ...

  3. 网络基础知识-bps、Bps、pps的区别

    在计算机科学中,bit是表示信息的最小单位,叫做二进制位:一般用0和1表示.Byte叫做字节,由8个位(8bit)组成一个字节(1Byte),用于表示计算机中的一个字符.bit(比特)与Byte(字节 ...

  4. linux中生成考核用的NTFS文件系统结构样例

    实验NTFS-1说明:NTFS-1.img是一个包含NTFS文件系统的磁盘镜像,请使用winhex手工方式读出这个文件系统内的指定文件,并回答其md5 HASH值.要求: 1.利用WINHEX手工方式 ...

  5. robotframework 脚本编写规范

    测试集.脚本 测试脚本的名字不要超过20个字符,文件类型应该为txt  名字必需易读且有意义(看名知意)  记住测试集的名字是自动根据文件.目录的名字创建的.后缀名会被截去,下划线会转换为空格,如果名 ...

  6. mui搜索框 搜索点击事件

    <div class="mui-input-row mui-search"> <input type="search" class=" ...

  7. scrapy-redis+selenium+webdriver解决动态代理ip和user-agent的问题(全网唯一完整代码解决方案)

    问题描述:在爬取一些反爬机制做的比较好的网站时,经常会遇见一个问题就网站代码是通过js写的,这种就无法直接使用一般的爬虫工具爬取,这种情况一般有两种解决方案 第一种:把js代码转为html代码,然后再 ...

  8. mysql 转换13位数字毫秒时间

    MySQL毫秒值和日期转换,MYSQL内置函数FROM_UNIXTIME: select FROM_UNIXTIME(t.createDate/1000,'%Y-%m-%d %h:%i:%s') as ...

  9. 王者荣耀交流协会 - 第7次Scrum会议(第三周)

    1.例会照片 照片由王超(本人)拍摄,组内成员刘耀泽,高远博,王磊,王玉玲,王超,任思佳,袁玥全部到齐. 2.时间跨度: 2017年11月2日 17:00 — 17:20 ,总计20分钟. 3.地 点 ...

  10. 字典树---2001 POJ Shortest Prefixes(找最短前缀)

    做的第一道字典树的题,算比较水的: -->>>:传送门 代码: #include <stdio.h> #include<stdlib.h> #define M ...