【题解】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. window命令

    查看端口占用命令: 开始--运行--cmd 进入命令提示符 输入netstat -aon 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在 ...

  2. hdu 4630 No Pain No Game(线段树+离线操作)

    No Pain No Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. MPTCP 源码分析(一) MPTCP的三次握手

    简述:      MPTCP依然按照正常的TCP进行三次握手,只是在握手过程中增加了MPTCP特有的信息.   建立过程      三次握手过程如下图所示: 左边客户端发送的第一个SYN包携带有客户端 ...

  4. 利用gearman同步mysql数据到redis

    一.Gearman 1.Gearman是一个分发任务的程序框架. 2.体系:a.client:发送一个jobb.server:找到合适的worker,把job交给该workerc.worker:处理j ...

  5. Php函数之end

    Php函数之end end()函数 (PHP 4, PHP 5, PHP 7) end - 将数组的内部指针指向最后一个单元 说明 mixed end ( array &$array ) en ...

  6. AlamoFireDemo

    // // ViewController.swift // AlamFireDemo // // import UIKit import Alamofire class ViewController: ...

  7. 给mysql root用户设置密码

    使用其他用户进入数据库, 用select PASSWORD('你要设置的密码'), 然后直接update mysql.user set  mysql.user.Password='你PASSWORD( ...

  8. 改变listview中item选中时文字的颜色

    摘要 当listview的某个item选中时,默认有个选中的高亮显示,如果你要自定义选中时的高亮显示效果,可以在listview中设置属性 android:listSelector="@dr ...

  9. Ansible@一个高效的配置管理工具--Ansible configure management--翻译(五)

    无书面许可请勿转载 高级Playbook Extra variables You may have seen in our template example in the previous chapt ...

  10. 搭建Squid反向代理服务器

    好吧,更新个文章,有段时间没写技术博文了.今天就说说squid反向代理这个服务,当然,这是在Linux下配置完成的.说自己没偏见似乎不可能 了.大概是相对喜欢Linux而已.但我从不否认Windows ...