POJ2411——Mondriaan's Dream(轮廓线dp入门)
来源:互联网 发布:生鲜网络销售平台 编辑:程序博客网 时间:2024/06/01 20:32
Mondriaan's Dream
Time Limit: 3000MS
Memory Limit: 65536KTotal Submissions: 15207
Accepted: 8771
Memory Limit: 65536KTotal Submissions: 15207
Accepted: 8771
Description
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.
Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Input
The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.
Output
For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.
Sample Input
1 21 31 42 22 32 42 114 110 0
Sample Output
10123514451205
题意:用1*2的砖块去铺满一个n*m的矩形的方案数
思路:算是最基本的轮廓线dp的题目。砖块只有横着放和竖着放两种状态。
首先当我们试图去填砖块(i,j)的时候,所有砖块(i1,j1),当其在(i,j)的左上方的时候,应该是已经被填好了的。
这样我们从(n-1)到0和(m-1)到0区遍历的话,就没有后效性的问题了。
所谓的轮廓线dp,是因为dp时的状态代表的是每一行没有填的最上方的砖块,一共m个。也就是相当于已经填好的砖块的轮廓。
然后枚举轮廓线状态去转移就好。
关于一些集合的运算可以去看看这篇博客。http://blog.csdn.net/say_c_box/article/details/52094549
<span style="font-size:14px;">#include<cstdio>#include<cstring>#include <string>#include <iostream>#include <algorithm>#include <vector>#include <map>#include <set>using namespace std;#define MAXN 200010#define INF 1000000000int d1[MAXN],d2[MAXN];int h[MAXN];int head[MAXN];int p[MAXN];set <int> s;vector <int> ans;struct edge{int v;int next;};edge G[MAXN*2];int num=0;int vis[MAXN];void add(int u,int v){G[num].v=v;G[num].next=head[u];head[u]=num++;};void dfs(int u,int d[]){ vis[u]=true; for(int k=head[u];k!=-1;k=G[k].next){ int v=G[k].v; if(!vis[v]){ d[v]=d[u]+1; dfs(v,d); } }}int n,m,d;int main(){ scanf("%d%d%d",&n,&m,&d); for(int i=0;i<m;i++){ scanf("%d",p+i); s.insert(p[i]); } for(int i=1;i<=n;i++){ if(s.count(i)==0) ans.push_back(i); } memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); for(int i=0;i<n-1;i++){ int a,b; scanf("%d%d",&a,&b); add(a,b); add(b,a); } h[1]=0; dfs(1,h); int max1=0; for(int i=0;i<m;i++){ if(h[p[i]]>h[p[max1]]) max1=i; } memset(vis,0,sizeof(vis)); d1[p[max1]]=0; dfs(p[max1],d1); int max2=0; for(int i=0;i<m;i++){ if(d1[p[i]]>d1[p[max2]]) max2=i; } memset(vis,0,sizeof(vis)); d2[p[max2]]=0; dfs(p[max2],d2); int cnt=0; for(int i=1;i<=n;i++){ if(d1[i]<=d&&d2[i]<=d) cnt++; } printf("%d\n",cnt); return 0;}</span>
0 0
- POJ2411——Mondriaan's Dream(轮廓线dp入门)
- poj2411——Mondriaan's Dream(状态压缩DP)
- poj2411 Mondriaan's Dream(轮廓线动态规划)
- POJ2411 Mondriaan's Dream(压缩DP)
- POJ2411:Mondriaan's Dream(状压dp)
- poj2411 Mondriaan's Dream(状压dp)
- POJ2411——Mondriaan's Dream
- POJ_P2411 Mondriaan's Dream(轮廓线DP)
- 【POJ2411】Mondriaan's Dream-状态压缩DP(插头DP?)
- poj - 2411 - Mondriaan's Dream(轮廓线dp)
- poj_2411 Mondriaan's Dream(轮廓线dp)
- POJ 2411 Mondriaan's Dream(插头DP,轮廓线)
- POJ-2411 Mondriaan's Dream(轮廓线dp)
- POJ2411 Mondriaan's Dream(状态压缩DP)
- poj2411 Mondriaan's Dream 状态压缩dp
- poj2411 mondriaan's dream 状压dp
- poj2411 Mondriaan's Dream 状态压缩dp
- poj2411 Mondriaan's Dream 插头dp做法
- 面试常见算法之---反转链表
- origin中实现柱状图倒立功能 + 设置X轴标注
- Android SelectorChapek工具使用
- 函数指针实现类似多态的特性
- bzoj 3289: Mato的文件管理(毒瘤毒瘤毒瘤题啊)
- POJ2411——Mondriaan's Dream(轮廓线dp入门)
- 机器学习(周志华) 参考答案 第五章 神经网络
- poj3617_简单贪心
- windows下设置由多个项目组成的解决方法的编译环境
- wait()、notify()和notifyAll()是 Object类 中的方法
- Android之数据存储
- Java基础之构造函数和重载
- 安卓luncher,实现自动启动,按home键回到luncher页面功能
- windows下spark环境搭建