【题解】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 ...
随机推荐
- 常见的Linux系统监控命令
1.free 显示当前系统未使用的和已使用的内存数目,还可以显示被内核使用的内存缓冲区 -b:以Byte为单位显示内存使用情况: -k:以KB为单位显示内存使用情况: -m:以MB为单位显示内存使 ...
- [转]解决Docker容器时间与主机不一致问题
原文: https://blog.csdn.net/luckystar689/article/details/76572046 https://stackoverflow.com/questions/ ...
- 用反射来了解Java中泛型的本质
这篇文章主要通过Class的Method来了解泛型的本质. 先new 两个List,一个不加类型限制,另外一个限制类型为String: ArrayList list = new ArrayList() ...
- Android源代码下载
清华大学AOSP镜像: https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
- python makestrans translate
""" 1. makestrans()用法 语法: str.maketrans(intab, outtab]); Python maketrans() 方法用于创建字符映 ...
- 关于ionic打包出错:ionic Unable to start the daemon process
一直试都没问题的ionic build android 今天竟然冒出了这个错误 Error:Unable to start the daemon process. This problem migh ...
- 关于八数码问题中的状态判重的三种解决方法(编码、hash、<set>)
八数码问题搜索有非常多高效方法:如A*算法.双向广搜等 但在搜索过程中都会遇到同一个问题.那就是判重操作(假设反复就剪枝),怎样高效的判重是8数码问题中效率的关键 以下关于几种判重方法进行比較:编码. ...
- Cocos2d-X中创建菜单项
Cocos2d-X中创建菜单的类: CCMenuItemFont:创建纯文本的菜单项 CCMenuItemAtlasFont:创建带有艺术字体的菜单项 CCMenuItemImage:用图片创建菜单项 ...
- ganlia安装配置文档
gangliaz在ubuntu中安装和配置很简单 1. 服务器端安装 sudo apt-get install ganglia-monitor ganglia-webfrontend rrdtool ...
- linux 下gtest 安装
cd gtest_dir //解压后的目录 mkdir mybuild # Create a directory to hold the build output. cd mybuild cmake ...