状压DP POJ 3254 Corn Fields
/*
状态压缩DP:先处理硬性条件即不能种植的,然后处理左右不相邻的,
接着就是相邻两行查询所有可行的种数并累加 写错一个地方差错N久:)
详细解释:http://www.tuicool.com/articles/JVzMVj
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e8;
int dp[MAXN][ << MAXN];
int st[ << MAXN];
int rem[ << MAXN]; int solve(int m)
{
int cnt = ;
int tot = << m;
for (int i=; i<tot; ++i)
{
if ((i & (i << )) == )
{
st[++cnt] = i;
}
} return cnt;
} void work(int n, int m, int cnt)
{
memset (dp, , sizeof (dp));
for (int i=; i<=cnt; ++i)
{
if ((st[i] & rem[]) == )
{
dp[][i] = ;
}
} for (int i=; i<=n; ++i)
{
for (int k=; k<=cnt; ++k)
{
if ((st[k] & rem[i]) == )
{
for (int j=; j<=cnt; ++j)
{
if (((st[j] & rem[i-]) == ) && ((st[j] & st[k]) == ))
dp[i][k] = (dp[i][k] + dp[i-][j]) % MOD;
}
}
}
} int ans = ;
for (int i=; i<=cnt; ++i)
{
ans = (ans + dp[n][i]) % MOD;
} printf ("%d\n", ans);
} int main(void) //POJ 3254 Corn Fields
{
#ifndef ONLINE_JUDGE
freopen ("F.in", "r", stdin);
#endif int n, m;
while (~scanf ("%d%d", &n, &m))
{
int cnt = solve (m); memset (rem, , sizeof (rem));
for (int i=; i<=n; ++i)
{
int x;
for (int j=; j<=m; ++j) //看错n和m
{
scanf ("%d", &x);
if (x == )
{
rem[i] = rem[i] | ( << (m-j));
}
}
} work (n, m, cnt);
} return ;
}
状压DP POJ 3254 Corn Fields的更多相关文章
- 状压 DP:[USACO06NOV] Corn Fields,[USACO13NOV] No Change
[USACO06NOV] Corn Fields (试题来源:Link ) 题目描述 Farmer John has purchased a lush new rectangular pasture ...
- 【状压DP】poj3254 Corn Fields
题意: 一块n*m的田,1表示这个地方可以种植,0代表这个地方不能种植.植物种植还必须满足两株植物不能相邻(横竖都不行).问共有几种种植方法,而且当什么都不种时认为是一种方法. 解题思路: 种植用1表 ...
- poj - 3254 - Corn Fields (状态压缩)
poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...
- POJ 3254 - Corn Fields - [状压DP水题]
题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...
- POJ 3254 Corn Fields (状压dp)
题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...
- 动态规划晋级——POJ 3254 Corn Fields【状压DP】
转载请注明出处:http://blog.csdn.net/a1dark 分析:刚开始学状压DP比较困难.多看看就发现其实也没有想象中那么难.这道题由于列数较小.所以将行压缩成二进制来看.首先处理第一行 ...
- [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp
题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...
- POJ - 3254 Corn Fields(状压DP)题解
思路: 参照blog,用状压DP做,和题解稍微有点不一样,我这里直接储存了状态而不是索引. 这一题的问题是怎么判断相邻不能种,我们用2进制来表示每一行的种植情况.我们将每一行所能够造的所有可能都打表( ...
- POJ 3254 Corn Fields (状压DP,轮廓线DP)
题意: 有一个n*m的矩阵(0<n,m<=12),有部分的格子可种草,有部分不可种,问有多少种不同的种草方案(完全不种也可以算1种,对答案取模后输出)? 思路: 明显的状压DP啦,只是怎样 ...
随机推荐
- [Effective JavaScript 笔记]第21条:使用apply方法通过不同数量的参数调用函数
apply()方法定义 函数的apply()方法和call方法作用相同,区别在于接收的参数的方式不同.apply()方法接收两个参数,一个是对象,一个是参数数组. apply()作用 1.用于延长函数 ...
- i3D的一篇Unity教程中的笔记
原地址:http://blog.sina.com.cn/s/blog_72b936d80100wwej.html 以下是i3D的一篇Unity教程中的笔记. i3D的这篇教程是[i3D.Next-Ge ...
- UIScrollview使用
改变内容偏移 - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at const ...
- poj2965枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20398 ...
- poj1094
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29539 Accepted: 10 ...
- Linux LAMP环境搭建
什么是LAMP Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了 ...
- PHP - 获取和设置include_path .
PHP - 获取和设置include_path 分类: PHP 2011-02-16 13:19 2818人阅读 评论(1) ...
- MVC3和MVC4相关问题
从TFS获取的MVC项目生成一直提示这个错误,我的VS中MVC3和MVC4都有,TFS项目中的MVC版本应该是MVC3的,现在我要用这个项目,但是一直是这个错误,请高手指点,积分不多了,见谅 程序集“ ...
- Two Sum I & II
Two Sum I Given an array of integers, find two numbers such that they add up to a specific target nu ...
- 【leetcode】3Sum
3Sum Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find a ...