题目传送门

 /*
状态压缩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的更多相关文章

  1. 状压 DP:[USACO06NOV] Corn Fields,[USACO13NOV] No Change

    [USACO06NOV] Corn Fields (试题来源:Link ) 题目描述 Farmer John has purchased a lush new rectangular pasture ...

  2. 【状压DP】poj3254 Corn Fields

    题意: 一块n*m的田,1表示这个地方可以种植,0代表这个地方不能种植.植物种植还必须满足两株植物不能相邻(横竖都不行).问共有几种种植方法,而且当什么都不种时认为是一种方法. 解题思路: 种植用1表 ...

  3. poj - 3254 - Corn Fields (状态压缩)

    poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...

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

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

  5. POJ 3254 Corn Fields (状压dp)

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

  6. 动态规划晋级——POJ 3254 Corn Fields【状压DP】

    转载请注明出处:http://blog.csdn.net/a1dark 分析:刚开始学状压DP比较困难.多看看就发现其实也没有想象中那么难.这道题由于列数较小.所以将行压缩成二进制来看.首先处理第一行 ...

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

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

  8. POJ - 3254 Corn Fields(状压DP)题解

    思路: 参照blog,用状压DP做,和题解稍微有点不一样,我这里直接储存了状态而不是索引. 这一题的问题是怎么判断相邻不能种,我们用2进制来表示每一行的种植情况.我们将每一行所能够造的所有可能都打表( ...

  9. POJ 3254 Corn Fields (状压DP,轮廓线DP)

    题意: 有一个n*m的矩阵(0<n,m<=12),有部分的格子可种草,有部分不可种,问有多少种不同的种草方案(完全不种也可以算1种,对答案取模后输出)? 思路: 明显的状压DP啦,只是怎样 ...

随机推荐

  1. [codeforces 293]B. Distinct Paths

    [codeforces 293]B. Distinct Paths 试题描述 You have a rectangular n × m-cell board. Some cells are alrea ...

  2. The content of element type "package" must match "(result-types?,interceptors?...

    错误:“The content of element type "package" must match "(result-types?,interceptors?,de ...

  3. [官方说明] 为什么ES4要分成两阶段?

    从ES4第一个版本发布到现在,已经有段时间了,绝大多数坛友都已经适应了ES4所带来的新封装模式,但仍有部分新人和坛友对ES4的两阶段模式带有不解或曲解.本帖将就ES4的两阶段意义做出解释说明,希望更多 ...

  4. 中位数与第K小元素

    算法实际上是模仿快速排序算法设计出来的,其基本思想也是对输入数组进行递归划分,与快速排序不同的是,它只对划分出来的子数组之一进行递归处理: int randompartition(int a[],in ...

  5. Android 中 设置TextView垂直滚动

    布局文件 android:scrollbars="vertical" android:singleLine="false" 代码文件 ctl_tv_conten ...

  6. android 自定义Dialog背景透明及显示位置设置

    先贴一下显示效果图,仅作参考: 代码如下: 1.自定义Dialog public class SelectDialog extends AlertDialog{ public SelectDialog ...

  7. JS匿名函数的理解

    js匿名函数的代码如下:(function(){ // 这里忽略jQuery 所有实现 })(); 半年前初次接触jQuery 的时候,我也像其他人一样很兴奋地想看看源码是什么样的.然而,在看到源码的 ...

  8. FireFox下上传控件的显示问题

    Chrome正常 FireFox显示不正常 上传控件一直有个问题,就是样式问题,解决方法就是用一个大的背景层挡住,然后点大的背景层去触发上传控件的Click事件. Html: <span id= ...

  9. eclipse debug source not fount

    1.选择Edit Source Lookup Path 2.选择Add 3.选择Java Project 4.选择相应的Project 进行OK确定即可 注意:做完以上的操作,要清除一下原来的断点,然 ...

  10. iOS 定制controller过渡动画 ViewController Custom Transition使用体会

    最近学习了一下ios7比较重要的一项功能,就是 controller 的 custom transition. 在ios7中,navigation controller 中就使用了交互式过渡来返回上级 ...