【题解】POJ2279 Mr.Young′s Picture Permutations dp
【题解】POJ2279 Mr.Young′s Picture Permutations dp
钦定从小往大放,然后直接dp。
\(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能dp。
然后你发现\(30^5\)开不下,但是你仔细观察由于它保证\(\sum < 30\)所以你只用开\(30^5 \div 5!\)就好了。
具体为什么我相信你会
//@winlere
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; typedef long long ll;
const int maxn=35;
unsigned int dp[maxn][maxn/2+1][maxn/3+1][maxn/4+1][maxn/5+1];
int l[7];
int main(){
int n;
while(cin>>n,n){
memset(dp,0,sizeof dp);
memset(l,0,sizeof l);
for(register int t=1;t<=n;++t)
cin>>l[t];
dp[0][0][0][0][0]=1;
for(register int t1=1;t1<=l[1];++t1){
for(register int t2=0;t2<=min(l[2],t1);++t2){
for(register int t3=0;t3<=min(l[3],t2);++t3){
for(register int t4=0;t4<=min(l[4],t3);++t4){
for(register int t5=0;t5<=min(l[5],t4);++t5){\
unsigned int&k=dp[t1][t2][t3][t4][t5];
if(t5)k+=dp[t1][t2][t3][t4][t5-1];
if(t4-1>=t5)k+=dp[t1][t2][t3][t4-1][t5];
if(t3-1>=t4)k+=dp[t1][t2][t3-1][t4][t5];
if(t2-1>=t3)k+=dp[t1][t2-1][t3][t4][t5];
if(t1-1>=t2)k+=dp[t1-1][t2][t3][t4][t5];
}
}
}
}
}
cout<<dp[l[1]][l[2]][l[3]][l[4]][l[5]]<<'\n';
}
return 0;
}
【题解】POJ2279 Mr.Young′s Picture Permutations dp的更多相关文章
- POJ2279 Mr Young's Picture Permutations
POJ2279 Mr Young's Picture Permutations 描述: 有N个学生合影,站成左对齐的k排,每行分别有N1,N2…NK个人,第一排站最后,第k排站之前.学生身高依次是1… ...
- 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)中的一个数 ...
- 轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- 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 ...
- 【杨氏矩阵+勾长公式】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 P2279 Mr. Young's Picture Permutations 题解
每日一题 day14 打卡 Analysis 五维dpf[a1,a2,a3,a4,a5]表示各排从左端起分别占了a1,a2,a3,a4,a5个人时合影方案数量然后我们枚举a1,a2,a3,a4,a5从 ...
- [POJ 2279] Mr. Young's Picture Permutations
[题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...
随机推荐
- 如果你还有以下这些现象,那你仍是PHP菜鸟:
最近看了个文章,写的很精辟,跟大家分享一下,这也是我的目标: 如果你还有以下这些现象,那你仍是PHP菜鸟:1. 不会利用如phpDoc这样的工具来恰当地注释你的代码:2. 对优秀的集成开发环境如Zen ...
- AndroidStudio短信验证功能收不到验证码
http://mob.com/第三方接口获取地址: 登陆过后点我的后台即可上传,管理应用.需注意的是,即使验证不通过,只要整合了短信验证的Jar包,每天都有20条免费验证短信.现在的mob.com只支 ...
- 【Javascript 基础】比较 undefined 和 null 值
JavaScript 中有两个特数值: undefined和null,在比较它们的时候需要留心.在读取未赋值的变量或试图读取对象没有的属性时得到的就是 undefined 值. <!DOCTYP ...
- [Fri, 3 Jul 2015 ~ Tue, 7 Jul 2015] Deep Learning in arxiv
Convolutional Color Constancy can this be used for training cnn to narrow the gap between different ...
- Windows无法删除文件 提示找不到该项目怎么办
1 如图所示,我想要删除某个文件,提示如图所示,一般用360的强力删除也不管用. 2 在桌面新建一个文本文档,并输入以下内容.保存为bat格式(比如Delete.bat).然后把这个删不掉的文件拖 ...
- Vector的一种实现(二)
增加了逆置迭代器的实现 以及swap功能 完整代码如下: #ifndef VECTOR_H_ #define VECTOR_H_ #include <stddef.h> #incl ...
- react-native 详解
1.获取主屏幕尺寸 // 导入类库 var Dimensions = require('Dimensions'); // 样式 const styles = StyleSheet.create({ c ...
- cpu、内存、硬盘
grep -c 'model name' /proc/cpuinfo
- js获取屏幕高度/浏览器高度
1.window.screen.height window.screen.height:设备显示屏的高度 (1)分辨率为1080px的显示屏 (2)手机屏 2.window.screen.avail ...
- 升级滑动销毁activity,随着手势的滑动而滑动的效果
文章开头先注明本滑动销毁是对 http://blog.csdn.net/xiaanming/article/details/20934541 这篇博客的内容进行一个小小的改动 添加向左滑动打开另外一个 ...