PKU 2411 Mondriaan's Dream 状态DP
以前做过这题,今天又写了一次,突然发现写了一个好漂亮的DFS……(是不是太自恋了 - -#)
代码:
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef __int64 ll; int n, m;
ll dp[][<<]; void dfs(int turn, int now, int next, int cnt) {
if (cnt > n) return ;
if (cnt==n) {
dp[turn+][next] += dp[turn][now];
return ;
}
if (!(now&(<<cnt))) { //如果cnt格没放,那就必须放
dfs(turn, now, next|(<<cnt), cnt+); //放一个竖着的
if (!(now&(<<(cnt+))) && (cnt<n-)) dfs(turn, now, next, cnt+); //放一个横着的
} else dfs(turn, now, next, cnt+); //如果这格被上一层的占了,那这一格就不能放任何东西
} int main() {
#ifdef Phantom01
freopen("PKU2411.txt", "r", stdin);
#endif // Phantom01 while (scanf("%d%d", &n, &m)!=EOF) {
if (n==&&m==) return ; if ((n*m)&) {
puts("");
continue;
}
memset(dp, , sizeof(dp));
dp[][] = ;
for (int i = ; i < m; i++)
for (int j = ; j < (<<n); j++) if (dp[i][j])
dfs(i, j, , );
printf("%I64d\n", dp[m][]);
}
}
PKU2411
PKU 2411 Mondriaan's Dream 状态DP的更多相关文章
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
- poj 2411 Mondriaan's Dream 轮廓线dp
题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...
- PKU P2411 Mondriaan's Dream
PKU P2411 Mondriaan's Dream 题目描述: Squares and rectangles fascinated the famous Dutch painter Piet Mo ...
- HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)
Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...
- Poj 2411 Mondriaan's Dream(压缩矩阵DP)
一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...
- POJ 2411 Mondriaan's Dream -- 状压DP
题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...
- Poj 2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- POJ 题目2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 13519 Accepted: 787 ...
随机推荐
- 洛谷P2939 [USACO09FEB]改造路Revamping Trails(最短路)
题目描述 Farmer John dutifully checks on the cows every day. He traverses some of the M (1 <= M <= ...
- 优动漫PAINT-绘制透明布料教程
原是一篇日语教程,觉得挺不错的,就劳烦会日语的朋友帮忙翻译了,特此分享!希望可以帮助到大家在绘画上的学习!原教程转载优动漫官网. 作者:JaneMere 相关资讯还可以关注www.dongmansof ...
- 转载:跟我一起写 Makefile
陈皓(http://my.csdn.net/haoel) 概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得 ...
- 洛谷P2770 航空路线问题 最小费用流
Code: #include<cstdio> #include<iostream> #include<algorithm> #include<vector&g ...
- 【模板】扩展中国剩余定理(EXCRT)
扩展中国剩余定理,是求解形如:$x\equiv a_{1}($ mod $b_{1})$$x\equiv a_{2}($ mod $b_{2})$$x\equiv a_{3}($ mod $b_{3} ...
- 常用的字符串方法 String ;
字符串: 1,str.charAt(num);//根据下标查找字符串中对应的字符,返回对应下标的字符; 2,str.charCodeAt(num);//字符串中下标对应的那位字符的 Unicode ...
- C#获取实例运行时间StopWatch类
在程序运行时有时需要获取某一步骤的操作时间,C#提供的StopWatch类可以很方便的实现这一目的. StopWatch sw=new StopWatch(); sw.Start(); //Do So ...
- 永远不要在MySQL中使用“utf8”
最近我遇到了一个 bug,我试着通过 Rails 在以“utf8”编码的 MariaDB 中保存一个 UTF-8 字符串,然后出现了一个离奇的错误: Incorrect string value: ‘ ...
- (50)与magento集成
我对接的是 odoo8 和 magento1.9.x 准备工作: l 服务器 装上mangento 组件 : $ pip install magento 装上 requests 组件:$ pip ...
- Python中文字符问题
Python中对中文字符的操作时常会使程序出现乱码 不全然管用的处理方法: 读取数据时使用encode编码为Bytes以保护数据 使用时转化为string并使用decode解码 如: title = ...