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 ...
随机推荐
- 使用java的Calendar对象获得当前日期的上几个度开始、结束时间
思路: 先获得当前季度的开始和结束日期,在当前日期的基础上往前推3个月即上个季度的开始和结束日期 /** * @param flag true:开始日期:false:结束日期 * @return */ ...
- Objective-C发展历史
Objective-C发展历史 苹果图标由来: 被咬了一口苹果的LOGO是为了纪念计算机科学的创始人阿兰· 麦席森· 图灵.当年图灵由于身为同性恋者,被强行 "治疗",在被迫注射大 ...
- jQuery分析(1) - 介绍
前言 web技术高速发展到现在已经出了现非常多的库或框架,库或框架实现方法也是五花八门.现在要实现一个web站点只需要根据自己的业务需求选择js框架即可快速完成.有些框架可以快速满足业务需求,但是有些 ...
- Spring Security Encryption三种加密方式
Encryption One-way encryption 单项加密,客户端将要传递的值先加密(使用特定的加密方法),将原值和加密好的值传递过去,服务器端将原始数据也进行一次加密(两者加密 ...
- yii2源码学习笔记(九)
Application是所有应用程序类的基类,接下来了解一下它的源码.yii2\base\Application.php. <?php /** * @link http://www.yiifra ...
- learn-python3
# learn-python3 这是我初学Python时写的一套Python基础示例程序.主要基于廖雪峰老师的Python3教程和<<深入理解Python>>. 感谢! 下 ...
- ServletContext全局变量初始化
Java部分 package com.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.ser ...
- typedef与define
一.typedef用法 typedef常用来定义一个标识符及关键字的别名,它生效是在语言编译过程,但它并不实际分配内存空间.typedef可以增强程序的可读性,以及标识符的灵活性,但它也有“非直观性” ...
- Tomcat启动分析(Tomcat7.0)
1)bin目录下的bootstrap.jar中的main方法启动Tomcat org.apache.catalina.startup.Bootstrap类下的main方法 可以看到Bootstrap类 ...
- C51应用 Modbs Rtu协议实现与KEPServerEx 通信
最近一客户要求使用STC12C5A60S2实现Modbus Rtu协议与KEPServerEx V4.0软件通信,采集单片机P2口每位的状态,设置P0口每位的状态,实现三路AD转换其中一路采集的是C0 ...