轮廓线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)中的一个数 ...
随机推荐
- spring配置mybatis3
mybatis官方网站:http://www.mybatis.org/mybatis-3/zh/configuration.html <!--第一步:加载配置数据库相关参数--> < ...
- 构建maven的web项目时注意的问题(出现Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 或者前端控制器无法加载)
构建项目后或者导入项目后,我们需要bulid path--->config build path 特别是maven的依赖一定要 发布到WEB_INF的lib下面,不然在发布项目的时候,这些依赖都 ...
- 【bzoj1059】[ZJOI2007]矩阵游戏 二分图最大匹配
题目描述 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏——矩阵游戏.矩阵游戏在一个N*N黑白方阵进行(如同国际象棋一般,只是颜色是随意的).每次可以对该矩阵进行两种操作:行交换 ...
- Linux命令——top
top命令可以实时动态地查看系统的整体运行情况,是一个综合了多方信息监测系统性能和运行信息的实用工具.通过top命令所提供的互动式界面,用热键可以管理. 语法 top(选项) 选项 -b:以批处理模式 ...
- msp430项目编程56
msp430综合项目---扩展项目六56 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结
- iOS 设置RGB色的宏
转自:http://lizhuang.iteye.com/blog/1931768 //RGB Color macro #define UIColorFromRGB(rgbValue) [UICol ...
- Can't connect to X11 window server using 'localhost:0.0' 的解决
Can't connect to X11 window server using 'localhost:0.0' 的解决 http://lufei-99999.blog.163.com/blog/st ...
- Effective Java P2 Item1 Consider static factory methods instead of constructors
获得一个类的实例的传统方法是公共的构造方法,还可以提供一个公共的静态工厂方法(一个返回值为该类实例的简单静态方法), 例如Boolean(boolean 的封装类) public static Boo ...
- 设计模式之装饰(Decorator)模式
设计模式之装饰(Decorator)模式 (一)什么是装饰(Decorator)模式 装饰模式,又称为包装模式,它以对客户端透明的方式扩张对象的功能,是继承关系的替代方案之一. 装饰模式可以在不使用创 ...
- Windows Server 远程桌面报错:No Remote Desktop License Servers Available
问题描述: 在用远程桌面访问Window Server服务器时,出现如下错误: The remote session was disconnected because there are no Rem ...