poj 3254
状态压缩 dp
dp[i][j] 为第 i 行状态为 j 的总数
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 2005
#define INF 0x3f3f3f3f
#define inf 10000000
#define MOD 100000000
#define ULL unsigned long long
#define LL long long using namespace std; int dp[15][1 << 13], mapp[1 << 13], sta[1 << 13];
int n, m, num; void init() {
memset(dp, 0, sizeof(dp));
memset(mapp, 0, sizeof(mapp));
num = 0;
for(int i = 0; i < (1<<m); ++ i) {
int d = i&(i << 1);
if(d == 0) sta[num++] = i;
}
// printf("num : %d\n", num);
} int main()
{
while(scanf("%d%d", &n, &m) == 2) {
init();
// puts("*********************");
// for(int i = 0; i < num; ++ i) {
// printf("%d ", sta[i]);
// }
// puts("**********************");
for(int i = 0; i < n; ++ i) {
for(int j = 0; j < m; ++ j) {
int a;
scanf("%d", &a);
if(a == 0) mapp[i] = mapp[i]|(1 << j);
}
}
for(int i = 0; i < num; ++ i) {
if((mapp[0] & sta[i]) == 0) {
dp[0][i] = 1;
}
}
for(int i = 1; i < n; ++ i) {
for(int j = 0; j < num; ++ j) {
if(mapp[i-1] & sta[j]) continue;
for(int q = 0; q < num; ++ q) {
if(mapp[i]&sta[q] || sta[j]&sta[q]) continue;
dp[i][q] += dp[i-1][j];
dp[i][q] %= MOD;
}
}
}
int ans = 0;
for(int i = 0; i < num; ++ i) {
ans += dp[n-1][i];
ans %= MOD;
}
printf("%d\n", ans);
}
return 0;
}
poj 3254的更多相关文章
- poj 3254 状压dp入门题
1.poj 3254 Corn Fields 状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...
- 状压DP POJ 3254 Corn Fields
题目传送门 /* 状态压缩DP:先处理硬性条件即不能种植的,然后处理左右不相邻的, 接着就是相邻两行查询所有可行的种数并累加 写错一个地方差错N久:) 详细解释:http://www.tuicool. ...
- POJ 3254 Corn Fields(状压DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13732 Accepted: 7216 Desc ...
- poj 3254 Corn Fields 国家压缩dp
意甲冠军: 要在m行n陆行,有一些格您可以种树,别人做不到的.不相邻的树,我问了一些不同的共同拥有的法律. 分析: 从后往前种,子问题向父问题扩展,当种到某一格时仅仅有他和他后面的n-1个格子的情况对 ...
- Corn Fields POJ - 3254 (状压dp)
题目链接: Corn Fields POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- poj - 3254 - Corn Fields (状态压缩)
poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- poj 3254 Corn Fields
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POJ 3254 Corn Fields (状压dp)
题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...
随机推荐
- Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
问题提示:Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. ...
- IOS学习2
1. #import,#include 和@class的区别 都引用一个类,根本定义区别:#include ,#import会把所有的copy一份到该文件 #import比#include的优势,im ...
- 常用按键ASCII码
ESC 27回车 13TAB 9Caps Lock 20Shift $10 Ctrl 17Alt 18空格 VK_SPACE 32退格 VK_BACK 8左徽标 VK_LWIN 91右徽标 VK_RW ...
- API - .add()
jQuery的 .add 很像一个collection, 官方的这个demo很形象的表达了这个意思. <!doctype html> <html lang="en" ...
- 02-线性结构3 Pop Sequence
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...
- Ruby处理二进制(未完成)
https://practicingruby.com/articles/binary-file-formats http://stackoverflow.com/questions/16821435/ ...
- 《Prism 5.0源码走读》Bootstrapper
Prism框架需要在应用程序启动的时候进行一些初始化的工作,Bootstrapper就是来做这些的,是其切入点. Bootstrapper主要要做的事有:创建和配置module catalog,创建D ...
- hdu 4609 3-idiots <FFT>
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意: 给定 N 个正整数, 表示 N 条线段的长度, 问任取 3 条, 可以构成三角形的概率为多 ...
- Windows下使用Visual Studio Code搭建Go语言环境
1.安装GO语言 下载地址: https://golang.org/dl/ Windows下直接运行安装GO语言即可. 安装成功. 安装完毕GO语言后,需要添加GOPATH环 ...
- Swift 1.2 正式发布 - 带来很多重大改进
Swift 1.2 随着 Xcode 6.3 Beta 正式发布了.这次的 beta 发布包含了对 Swift 编译器显著的改进.还有对 Swift 语言本身的新特性的增加.这篇文章介绍下主要部分. ...