【POJ 2411】 Mondriaan's Dream
【题目链接】
【算法】
很明显,我们可以用状态压缩动态规划解决此题
f[n][m]表示n-1行已经放满,第n行状态为m的合法的方案数
状态转移方程很好推
注意这题时限较紧,注意加一些小优化
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 12 long long n,m;
long long f[MAXN][<<MAXN],ans[MAXN][MAXN]; template <typename T> inline void read(T &x) {
long long f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
inline bool ok(long long s) {
long long i = ;
while (i < m) {
if (s & ( << i)) {
if (!(s & ( << (i + ))))
return false;
i += ;
continue;
}
i++;
}
return true;
}
inline bool check(long long now,long long last) {
long long i = ;
while (i < m) {
if (!(last & ( << i))) {
if (!(now & ( << i))) return false;
i++;
continue;
} else {
if ((now & ( << i)) && (now & ( << (i + ))) && (last & ( << (i + )))) {
i += ;
continue;
}
if (!(now & ( << i))) {
i++;
continue;
}
return false;
}
}
return true;
}
inline void solve(long long n,long long m) {
long long i,j,k,
MASK = ( << m) - ;
for (i = ; i <= MASK; i++) if (ok(i)) f[][i] = ; else f[][i] = ;
for (i = ; i <= n; i++) {
for (j = ; j <= MASK; j++) {
f[i][j] = ;
for (k = ; k <= MASK; k++) {
if (check(j,k))
f[i][j] += f[i-][k];
}
}
}
ans[n][m] = ans[m][n] = f[n][MASK];
writeln(f[n][MASK]);
} int main() { memset(ans,,sizeof(ans));
while (true) {
read(n); read(m);
if (!n && !m) break;
if (n & && m & ) ans[n][m] = ans[m][n] = ;
if (ans[n][m] != -) {
writeln(ans[n][m]);
continue;
}
if (n < m) swap(n,m);
solve(n,m);
} return ;
}
【POJ 2411】 Mondriaan's Dream的更多相关文章
- 【POJ 2411】【Mondriaans Dream】 状压dp+dfs枚举状态
题意: 给你一个高为h,宽为w的矩阵,你需要用1*2或者2*1的矩阵填充它 问你能有多少种填充方式 题解: 如果一个1*2的矩形横着放,那么两个位置都用二进制1来表示,如果是竖着放,那么会对下一层造成 ...
- 【POJ2411】Mondriaan's Dream(轮廓线DP)
[POJ2411]Mondriaan's Dream(轮廓线DP) 题面 Vjudge 题解 这题我会大力状压!!! 时间复杂度大概是\(O(2^{2n}n^2)\),设\(f[i][S]\)表示当前 ...
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
随机推荐
- BZOJ 3675 [Apio2014]序列分割 (斜率优化DP)
题目链接 BZOJ 3675 首先最后的答案和分割的顺序是无关的, 那么就可以考虑DP了. 设$f[i][j]$为做了$i$次分割,考虑前$j$个数之后的最优答案. 那么$f[i][j] = max( ...
- HDU - 5974 A Simple Math Problem (数论 GCD)
题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...
- Spring基于Setter函数的依赖注入(DI)
以下内容引用自http://wiki.jikexueyuan.com/project/spring/dependency-injection/spring-setter-based-dependenc ...
- android 打开浏览器指定网页
<?xml version="1.0" encoding="utf-8"?> <!-- 定义当前布局的基本LinearLayout --> ...
- sqlfairy用法
要画一个数据库的ER图,我比较懒,就想用工具来生成. 找了一下,发现一个不错的工具,名字叫sal-fairy 很强大,可以有很多用处. 其中有一个命令sqlt-graph,可以完成生成ER图. 用法如 ...
- [转]gzip,bzip2,tar,zip命令使用方法详解
原文:http://blog.chinaunix.net/uid-20779720-id-2547669.html 1 gzipgzip(1) 是GNU的压缩程序.它只对单个文件进行压缩.基本用法如下 ...
- [Javascript] Cancel A Promise Using AbortController
The AbortController interface enables us to cancel a one or more DOM requests. In this lesson, we wi ...
- com.sun.jdi.InvocationException occurred invoking method 异常
参考链接:https://stackoverflow.com/questions/4123628/com-sun-jdi-invocationexception-occurred-invoking-m ...
- requirejs中的define
关于requirejs中的define的原理理解 我们已经了解到模块模式是为单例创建私有变量和特权方法的.一个最基本的例子: var foo=(function(){ var something= ...
- AIX下RAC搭建 Oracle10G(二)主机配置
AIX下RAC搭建系列 AIX下RAC搭建 Oracle10G(二)主机配置 环境 节点 节点1 节点2 小机型号 IBM P-series 630 IBM P-series 630 主机名 AIX2 ...