【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 ...
随机推荐
- ubuntu下用webbench做网站压力测试
安装依赖 exuberant-ctags sudo apt-get install exuberant-ctags 下载源码并安装 wget http://blog.s135.com/soft/lin ...
- Bruce Eckel:编程生涯
大家总是问一个错误的问题:“我应该学习C++还是Java?”在本文中,我将告诉大伙儿:对于选择编程生涯真正需要关注的是哪些问题. 请注意,这篇文章的目标读者并不是那些已经做出自己选择的人.(对于这些人 ...
- STM32调试问题
1.JLINK V8 error:flash download failed - could not load file: Options for Target 'Targer 1'下的菜单下Outp ...
- org.xml.sax.SAXParseException: 元素内容必须由格式正确的字符数据或标记组成,的错误问题
当时在mapper其中的一个语句是case when ISNULL(b.c_truename) || LENGTH(TRIM(b.c_truename)) < 1 then b.c_ch_nam ...
- Object源码
1.Object是所有类的父类,默认会继承Object. 2.Object类中常用的方法有:getClass().hashCode().equals().clone().toString().fina ...
- IntelliJ IDE 各种插件的安装和使用
插件的安装和使用持续的更新中...........................................................
- Ubuntu 16.04下快速在当前目录打开终端的快捷键设置
说明:不一定每次都准确打开,80%的机会是行的. 原理:使用xdotool模拟键盘按键,打开的文件夹管理界面,然后通过Ctrl+L获取地址栏地址,然后传递到终端上. 安装: 1.安装xdotool s ...
- ubuntu16.04安装mysql5.7.15
1.在官网下载mysql安装包 直接选择第一个下载好了就行 2.进入你的下载文件夹下面 键入命令: tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb ...
- linux 系统命令----修改主机名
1. hostname ***** 2.修改/etc/sysconfig/network 3./etc/hosts 最后第三步没有必要!
- yum gd linux
32位操作系统安装命令:[root@localhost ~]# yum install php-gd*64位操作系统安装命令:[root@localhost ~]# yum install php-g ...