轮廓线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)中的一个数 ...
随机推荐
- 送信 okhttp
package jp.co.gunmabank.minefocus.accountApp import android.content.Intentimport android.graphics.Co ...
- Tomcat 调优技巧
Tomcat 调优技巧:1.Tomcat自身调优: ①采用动静分离节约Tomcat的性能: ②调整Tomcat的线程池: ③调整Tomcat的连接器: ④修改Tomcat的运行模式: ⑤禁用AJP连接 ...
- day02-菜单处理
解决力度到按钮的级别 ----------------------------------------------------------------------------------------- ...
- EC++学习笔记(五) 实现
条款26:尽可能延后变量定义式的出现时间 尽可能延后变量的定义,知道非得使用该变量的前一刻为止方法A: Widget W; ; i < n; ++i) { W = ... } 方法B: ; i ...
- 关于错误Access Violation和too many consecutive exceptions 解决方法
关于错误Access Violation和too many consecutive exceptions 解决方法 “如果DLL中用到了DELPHI的string类型,则DLL和主程序中都需要加上Sh ...
- 什么是 Linux
什么是Linux Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX工具软件.应用程序和网络 ...
- CMDB资产管理系统的数据表设计
Server表: asset = models.OneToOneField('Asset') 主机名(hostname) sn号(sn) 制造商(manufacture) 系统(os_platform ...
- ros使用罗技f710无线控制手柄
参考:blog.csdn.net/hcx25909/article/details/9042469 罗技F710无线控制手柄ROS下使用说明 安装手柄相关的包和驱动 sudo apt-get inst ...
- FastDFS介绍和搭建(转载)
FastDFS介绍和配置过程--http://blog.51cto.com/ylw6006/948729 FastDFS的五篇文章--http://www.cnblogs.com/smartycity ...
- luogu P1043 数字游戏
题目描述 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共n个),你要按顺序将其分 ...