【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 ...
随机推荐
- PSO(Thepopularity-similarity-oplimization) modol
PSO(Thepopularity-similarity-oplimization) modol 在这篇文章里,我们试图将社交关系构成的网络结构从纷繁复杂的具体场景.细节条件中剥离出来,单单从个体间连 ...
- MySQL、Hive以及MySQL Connector/J安装过程
MySQL安装 ①官网下载mysql-server(yum安装) wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch. ...
- Android SDK Manager 更新时的“https://dl-ssl.google.com refused”错误
Android SDK Manager 消除SDK更新时的“https://dl-ssl.google.com refused”错误 消除SDK更新时,有可能会出现这样的错误:Download int ...
- 中国剩余定理 & 欧拉函数 & 莫比乌斯反演 & 狄利克雷卷积 & 杜教筛
ssplaysecond的博客(请使用VPN访问): 中国剩余定理: https://ssplaysecond.blogspot.jp/2017/04/blog-post_6.html 欧拉函数: h ...
- Java代码规范和质量检查插件-Checkstyle(官方资源)
其实Checkstyle是一个JAR包,然后第三方开发者开发了Eclipse/IDEA的插件. 官网: https://github.com/checkstyle/checkstyle Eclipse ...
- HDC与CDC相互转换
转自loop_k原文 HDC与CDC相互转换 概念 首先说一下什么是DC(设备描述表):Windows应用程序通过为指定设备(屏幕,打印机等)创建一个设备描述表(Device Context, DC) ...
- http://www.yiibai.com/java8/java8_temporaladjusters.html
原文:http://www.yiibai.com/java8/java8_temporaladjusters.html TemporalAdjuster 是做日期数学计算.例如,要获得“本月第二个星期 ...
- Apdex——衡量服务器性能的标准
Apdex 全称是 Application Performance Index,是由 Apdex 联盟开放的用于评估应用性能的工业标准.Apdex 联盟起源于 2004 年,由 Peter Sevci ...
- FIR300M刷openwrt
淘宝看到一款FIR300M路由器,当时只要19.9元.图便宜就买了. Hardware Architecture: MIPS Vendor: MediaTek (Ralink) Bootloader: ...
- Java Unit Testing - JUnit & TestNG
转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...