轮廓线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)中的一个数 ...
随机推荐
- 自定义Title
xml: <jp.co.view.TitleLayout android:id="@+id/titleLayout" android:layout_width="m ...
- Python之转换py文件为无需依赖python环境的exe文件的方法
在日常工作中,使用python脚本开发快速敏捷,但是其代码是可见的,而且充分的依赖python开发环境.为了达到保护我们源码的目的,或者不依赖python开发环境使用python脚本,将其转换成可以直 ...
- 【bzoj2901】矩阵求和 前缀和
题目描述 给出两个n*n的矩阵,m次询问它们的积中给定子矩阵的数值和. 输入 第一行两个正整数n,m. 接下来n行,每行n个非负整数,表示第一个矩阵. 接下来n行,每行n个非负整数,表示第二个矩阵. ...
- 【Luogu】P1417烹调方案(排序01背包)
题目链接 对食材进行排序,重载运算符代码如下: struct food{ long long a,b,c; bool operator <(const food &a)const{ re ...
- 【Luogu】P1155双栈排序(二分图)
题目链接在此 此题一开始写了个深搜,过了30%的数据,也就是n<=10的那一段.... 然后看了题解发现这是个二分图的判断. 我们先举例子找到不能放进一个栈里的规律.设有数列[2,3,1,4] ...
- eclipse导入svn检出的maven项目问题
1.修改项目jdk环境和编译环境.消除红叉. 2.windows-preferences-java-installed jres,修改工作空间的jdk,在Default vm arguments栏中添 ...
- MATLAB(1)
前言 之前经常用MATLAB,却不小心停留在了舒适区,连基本的调试方法都没有掌握.本文主要是对MATLAB程序调试中的一般方法进行总结,也是自己学习的记录.全文大致分为三个段落: 1)代码内调试: 2 ...
- 标准C程序设计七---02
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- LeetCode OJ--Search in Rotated Sorted Array II
http://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/ 如果在数组中有重复的元素,则不一定说必定前面或者后面的一半是有序的 ...
- Hdu5921 Binary Indexed Tree
Hdu5921 Binary Indexed Tree 思路 计数问题,题目重点在于二进制下1的次数的统计,很多题解用了数位DP来辅助计算,定义g(i)表示i的二进制中1的个数, $ans = \su ...