poj 3465 Corn Fields 状态压缩
题目链接:http://poj.org/problem?id=3254
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int moder = 1e8;
const int maxe = ;
const int maxn = ;
const int INF = 0x3f3f3f; int dp[maxn][<<maxn];
//dp[i][state] 表示第i行的state这个状态方案个数。dp[i][j] += dp[i-1][j']; 这里需要列举完所有可能的状态j'能退出j。
int G[maxn]; bool isok(int x){ //判断x是否有相邻的。
if(x & (x<<)) return false;
return true;
} int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int M,N;
cin>>M>>N;
for(int i=;i<=M;i++){
G[i] = ;
for(int j=;j<N;j++){
int a;
scanf("%d",&a);
if(a) G[i] |= (<<j);
}
}
G[] = ;
memset(dp,,sizeof(dp));
dp[][] = ;
for(int i=;i<=M;i++){ //i指向操作的行。
for(int upstate=;upstate<(<<N);upstate++)
if(isok(upstate)){
if(dp[i-][upstate])
for(int nowstate=;nowstate<(<<N);nowstate++){ //printf("%d\n",nowstate);
if(!isok(nowstate)) continue;
if(nowstate & upstate) continue; //upstate有1的地方nowstate决不允许有1.
if(nowstate & (~G[i])) continue; //G[i] 有0的地方nowstate决不允许有1.
dp[i][nowstate] += dp[i-][upstate];
}
}}
int ans = ;
for(int i=;i<(<<N);i++){
if(!isok(i)) continue;
ans = (ans + dp[M][i])%moder;
}
printf("%d\n",ans);
}
poj 3465 Corn Fields 状态压缩的更多相关文章
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [ACM] POJ 3254 Corn Fields(状态压缩)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8062 Accepted: 4295 Descr ...
- POJ 3254 Corn Fields 状态压缩DP (C++/Java)
id=3254">http://poj.org/problem? id=3254 题目大意: 一个农民有n行m列的地方,每一个格子用1代表能够种草地,而0不能够.放牛仅仅能在有草地的. ...
- POJ 3254 Corn Fields (状态压缩DP)
题意:在由方格组成的矩形里面种草,相邻方格不能都种草,有障碍的地方不能种草,问有多少种种草方案(不种也算一种方案). 分析:方格边长范围只有12,用状态压缩dp好解决. 预处理:每一行的障碍用一个状态 ...
- POJ 3254 Corn Fields状态压缩DP
下面有别人的题解报告,并且不止这一个状态压缩题的哦···· http://blog.csdn.net/accry/article/details/6607703 下面是我的代码,代码很挫,绝对有很大的 ...
- POJ 3254 Corn Fields 状态压缩
这题对我真的非常难.实在做不出来,就去百度了,搜到了一种状压DP的方法.这是第一种 详细见凝视 #include <cstdio> #include <cstring> #in ...
- poj - 3254 Corn Fields (状态压缩dp入门)
http://poj.org/problem?id=3254 参考:http://blog.csdn.net/accry/article/details/6607703 农夫想在m*n的土地上种玉米, ...
- poj Corn Fields 状态压缩dp。
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5763 Accepted: 3052 Descr ...
随机推荐
- JavaEE web.xml 中ContextLoaderListener的解析
ContextLoaderListener监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在 ...
- C#转Python计划
1.学习python语法,完成python_cookbook上的代码. 目标:熟悉python语法和开发习惯,以及调试方法. 2.学习使用Django框架,完成一个基于Django框架的项目,发布到g ...
- Java8 map和reduce
map final List<Integer> numbers = Arrays.asList(1, 2, 3, 4); final List<Integer> doubleN ...
- 半质数的个数 csdn 英雄会 高校俱乐部
2·14 情人&元宵节专题:半质数的个数. 题目:质数是大家熟知的概念,我们定义一个半质数的概念:如果一个数恰好是两个质数的乘积(可以相同),则称它为半质数.前几个半质数是 4, 6, 9, ...
- C#快递单号查询源码
源码本人测试过,没有啥问题,能查询快递单号,支持的快递还挺多,圆通快递.申通快递.韵达快递的都支持单号查询的,程序是通过向爱快递(www.aikuaidi.cn)接口传输参数来查询快递单号,我直接把代 ...
- 开启g++ 编辑器 c++11特性
以前都是在windows下用vs和cvi写C和C++代码,最近练习Linux下的使用. 编译的时候使用C++11的新特性比如auto 和 iteration特性都报不支持,后来在知乎看到答案需要在编译 ...
- tornado远远不止
大家的回答都有点片面,更多的关注web框架成,其实tornado远远不止这些,且听我慢慢到来1.高性能的网络库,这可以和gevent,twisted,libevent等做对.提供了异步io支持,超时事 ...
- 为什么这么多Python框架
原文:http://bitworking.org/news/Why_so_many_Python_web_frameworks BitWorking This is Joe Gregorio's wr ...
- 字符串搜索算法Boyer-Moore
整理日: 2015年2月16日 1. 主要特征 假设文本串text长度为n,模式串pattern长度为m,BM算法的主要特征为: 从右往左进行比较匹配(一般的字符串搜索算法如KMP都是从从左往右进行匹 ...
- NEURAL NETWORKS, PART 2: THE NEURON
NEURAL NETWORKS, PART 2: THE NEURON A neuron is a very basic classifier. It takes a number of input ...