轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations



$ solution: $
首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度应该从后面到前面减少)。这个已经很提示我们轮廓线DP了。而且这一题的数据范围也十分的小:行数不超过五行,人数不多于三十人。这么小的数据范围基本上可以断定是DP了。
然后这种带限制条件的我们可以想办法满足,比如说身高问题我们一般都会采取填人的办法(这一题按身高从大到小填(当然反过来也可以)),然后我们就可以将这个身高问题转换成如果前面的那一行比我们要填的这一行要长那么我们这一行就不能填,然后直接将符合条件的情况转移即可。(详细见代码)
$ code: $
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define db double
#define inf 0x7fffffff
#define rg register int
using namespace std;
int n;
int a[7];
ll f[31][17][11][9][7];
inline int qr(){
register char ch; register bool sign=0; rg res=0;
while(!isdigit(ch=getchar())) if(ch=='-')sign=1;
while(isdigit(ch)) res=res*10+(ch^48),ch=getchar();
return sign?-res:res;
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
while(n=qr()){
for(rg i=1;i<=5;++i) a[i]=0;
for(rg i=1;i<=n;++i) a[i]=qr();
for(rg i=0;i<=a[1];++i)
for(rg j=0;j<=a[2];++j)
for(rg p=0;p<=a[3];++p)
for(rg q=0;q<=a[4];++q)
for(rg k=0;k<=a[5];++k)
f[i][j][p][q][k]=0;
f[0][0][0][0][0]=1;
for(rg i=0;i<=a[1];++i)
for(rg j=0;j<=a[2];++j)
for(rg p=0;p<=a[3];++p)
for(rg q=0;q<=a[4];++q)
for(rg k=0;k<=a[5];++k){
if(!f[i][j][p][q][k])continue;
if(k<a[5])f[i][j][p][q][k+1]+=f[i][j][p][q][k];
if(q<k&&q<a[4])continue;
if(q<a[4])f[i][j][p][q+1][k]+=f[i][j][p][q][k];
if(p<q&&p<a[3])continue;
if(p<a[3])f[i][j][p+1][q][k]+=f[i][j][p][q][k];
if(j<p&&j<a[2])continue;
if(j<a[2])f[i][j+1][p][q][k]+=f[i][j][p][q][k];
if(i<j&&i<a[1])continue;
if(i<a[1])f[i+1][j][p][q][k]+=f[i][j][p][q][k];
}
printf("%lld\n",f[a[1]][a[2]][a[3]][a[4]][a[5]]);
}
return 0;
}
轮廓线DP:poj 2279 Mr. Young's Picture Permutations的更多相关文章
- 【杨氏矩阵+勾长公式】POJ 2279 Mr. Young's Picture Permutations
Description Mr. Young wishes to take a picture of his class. The students will stand in rows with ea ...
- [POJ 2279] Mr. Young's Picture Permutations
[题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...
- POJ P2279 Mr. Young's Picture Permutations 题解
每日一题 day14 打卡 Analysis 五维dpf[a1,a2,a3,a4,a5]表示各排从左端起分别占了a1,a2,a3,a4,a5个人时合影方案数量然后我们枚举a1,a2,a3,a4,a5从 ...
- 【题解】POJ2279 Mr.Young′s Picture Permutations dp
[题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...
- POJ2279 Mr Young's Picture Permutations
POJ2279 Mr Young's Picture Permutations 描述: 有N个学生合影,站成左对齐的k排,每行分别有N1,N2…NK个人,第一排站最后,第k排站之前.学生身高依次是1… ...
- Mr. Young's Picture Permutations
Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增 ...
- bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式
2483: Pku2279 Mr. Young's Picture Permutations Time Limit: 1 Sec Memory Limit: 128 MB Description ...
- poj2279——Mr. Young's Picture Permutations
Description Mr. Young wishes to take a picture of his class. The students will stand in rows with ea ...
- poj2279 Mr. Young's Picture Permutations[勾长公式 or 线性DP]
若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数 ...
随机推荐
- Oracle学习笔记整理手册
文章目录(1)Oracle正则匹配使用(2)Oracle修改有数据的数据字段类型(3)Oracle表数据回滚语句(4)sql筛选出记录数大于2的记录(5)oracle同义词(6)oracle内外连接( ...
- Log4j2异步情况下怎么防止丢日志的源码分析以及队列等待和拒绝策略分析
org.apache.logging.log4j.core.async.AsyncLoggerConfigDisruptor以下所有源码均在此类中首先我们看下log4j2异步队列的初始化 从这里面我们 ...
- PHP html_entity_decode() 函数
html_entity_decode(string,flags,character-set) 把 HTML 实体转换为字符. html_entity_decode() 函数是 htmlentities ...
- [NOIP2012T3]开车旅行
题目描述 NOIP 2012 提高组 题3小 A 和小 B 决定利用假期外出旅行,他们将想去的城市从 1 到 N 编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 ...
- DBA总结
HA MHA(1)从宕机崩溃的master保存二进制日志事件(binlog events);(2)识别含有最新更新的slave:(3)应用差异的中继日志(relay log)到其他的slave:(4) ...
- UNIDAC如何驱动MSSQL2000
UNIDAC如何驱动MSSQL2000 如下图,PROVIDER必须设置为PRSQL.默认的PRAUTO,如果操作系统是XP可以,如果是WIN7以上的,不可以. 原因是MSSQL NATIVE 11已 ...
- BUPT复试专题—哈夫曼树(2010)
https://www.nowcoder.com/practice/162753046d5f47c7aac01a5b2fcda155?tpId=67&tqId=29635&tPage= ...
- chrome插件网站
chrome插件网站 http://chromecj.com/
- IDEA中Thrift插件配置
方法一:直接在IDEA界面中配置 打开IDEA的插件中心,搜索 Thrift 即可安装 方法二:手动下载Thrift插件安装 有时像在IDEA中安装Lombok插件一样,有时由于网络原因,方法一不奏效 ...
- poj(1011)——Sticks(经典的dfs+剪枝)
题目的大致意思是: 如今有n根木棍,然后须要把它们拼成相同长度的木棍,问满足这个条件的最短的长度是多少? 想法嘛:那肯定是dfs把长度搜一遍就好,但问题的关键是这里会超时.那么就要用到剪枝的原理了. ...