【题解】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的更多相关文章

  1. POJ2279 Mr Young's Picture Permutations

    POJ2279 Mr Young's Picture Permutations 描述: 有N个学生合影,站成左对齐的k排,每行分别有N1,N2…NK个人,第一排站最后,第k排站之前.学生身高依次是1… ...

  2. 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 ...

  3. poj2279 Mr. Young's Picture Permutations[勾长公式 or 线性DP]

    若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数 ...

  4. 轮廓线DP:poj 2279 Mr. Young's Picture Permutations

    poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...

  5. Mr. Young's Picture Permutations

    Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增 ...

  6. bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式

    2483: Pku2279 Mr. Young's Picture Permutations Time Limit: 1 Sec  Memory Limit: 128 MB Description   ...

  7. 【杨氏矩阵+勾长公式】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 ...

  8. 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从 ...

  9. [POJ 2279] Mr. Young's Picture Permutations

    [题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...

随机推荐

  1. 【转】VirtualBox网卡设置

    原文: https://blog.csdn.net/jwpker/article/details/45870903 ------------------------------------------ ...

  2. Android SqliteOpenHelper详解

    一. SQLite介绍 SQLite是android内置的一个很小的关系型数据库. SQLite的官网是http://www.sqlite.org/,可以去下载一些文档或相关信息. 博客中有一篇有稍微 ...

  3. notepad++ 在每一行最后加上逗号

    1.全选缩进对齐 2.替换功能,入下全部替换 3.在入下替换 4.结果 完成!

  4. 从零单排之玩转Python安全编程(II)

    转自:http://www.secpulse.com/archives/35893.html 都说Python大法好,作为一名合格的安全从业人员,不会几门脚本语言都不好意思说自己是从事安全行业的. 而 ...

  5. redhat 用yum安装的apache、mysql一般默认安装在哪个目录下?

    使用yum安装成功后,使用rpm -qa | grep httpd和rpm -qa | grep mysql查看是否安装成功然后使用rpm -ql httpd和rpm -ql mysql查看安装文件都 ...

  6. Eclipse 使用 SVN 插件后改动用户方法汇总

    判定 SVN 插件是哪个 JavaH 的处理方法 SVNKit 的处理方法 工具自带改动功能 删除缓存的秘钥文件 其他发表地点 判定 SVN 插件是哪个 常见的 Eclipse SVN 插件我知道的一 ...

  7. Oracle 修改表名

    .ALTER TABLE T_PLAT_KEYWORD_STATISTIC RENAME TO T_PLAT_KEYWORD; .create new_table as select * from o ...

  8. mysql :安装过程中的问题

    安装mysql  选择路径的问题 出现如下问题:说明之前安装过mysql,写在的不干净

  9. 如何从一个1G的文件中找到你所需要的东西

    如何从一个1G的文件中找到你所需要的东西,这个问题貌似面试的时候会经常问到.不过不论你用什么语言,肯定逃脱不了按指针读或者按块读. 这里介绍python的用法.本人亲自实验了,速度还可以. 如果你的文 ...

  10. PHP面试题及答案解析(6)—PHP网络编程

    1.禁用COOKIE后SEESION还能用吗? 可以,COOKIE和SESSION都是用来实现会话机制的,由于http协议是无状态的,所以要想跟踪一个用户在同一个网站之间不同页面的状态,需要有这么一个 ...