题目:

有N个学生合影,站成左端对齐的k排,每排有 \(N-1,N_2,…N_k\)个人,第一排在最后面。学生的身高互不相同,分别为\(1-N\),并且合影时要求每一排从左往右身高递减,每一列从后往前身高递减,问有多少种安排合影的方案 。\(N <=30, k <=5\)


//此题默认 —— N1 >= N2 >= N3 >= ... >= Nk
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
typedef long long ll;
typedef double db;
const db EPS = 1e-9;
using namespace std; int row[10],n;
ll dp[32][32][32][32][32]; int main()
{
while(~scanf("%d",&n)){
if(!n) break;
memset(row,0,sizeof row);
rep(i,1,n) scanf("%d",&row[i]);
rep(a1,0,row[1])
rep(a2,0,row[2])
rep(a3,0,row[3])
rep(a4,0,row[4])
rep(a5,0,row[5]) dp[a1][a2][a3][a4][a5] = 0;
dp[0][0][0][0][0] = 1;
rep(a1,0,row[1])
rep(a2,0,row[2]){
if(a1 != row[1] && a2 > a1) continue;
rep(a3,0,row[3]){
if(a2 != row[2] && a3 > a2) continue;
rep(a4,0,row[4]){
if(a3 != row[3] && a4 > a3) continue;
rep(a5,0,row[5]){
if(a4 != row[4] && a5 > a4) continue;
if(a1 < row[1])
dp[a1+1][a2][a3][a4][a5] += dp[a1][a2][a3][a4][a5];
if(a2 < row[2] && ((a2 < a1) || (a1 == row[1])))
dp[a1][a2+1][a3][a4][a5] += dp[a1][a2][a3][a4][a5];
if(a3 < row[3] && ((a3 < a2) || (a2 == row[2])))
dp[a1][a2][a3+1][a4][a5] += dp[a1][a2][a3][a4][a5];
if(a4 < row[4] && ((a4 < a3) || (a3 == row[3])))
dp[a1][a2][a3][a4+1][a5] += dp[a1][a2][a3][a4][a5];
if(a5 < row[5] && ((a5 < a4) || (a4 == row[4])))
dp[a1][a2][a3][a4][a5+1] += dp[a1][a2][a3][a4][a5];
}
}
}
}
printf("%lld\n",dp[row[1]][row[2]][row[3]][row[4]][row[5]]);
}
return 0;
}

【POJ 2279】Mr. Young’s Picture Permutations【线性DP】的更多相关文章

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

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

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

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

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

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

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

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

  6. POJ2279 Mr Young's Picture Permutations

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

  7. 【题解】POJ2279 Mr.Young′s Picture Permutations dp

    [题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...

  8. Mr. Young's Picture Permutations

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

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

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

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

随机推荐

  1. 每天5分钟复习OpenStack(十一)Ceph部署

    在之前的章节中,我们介绍了Ceph集群的组件,一个最小的Ceph集群包括Mon.Mgr和Osd三个部分.为了更好地理解Ceph,我建议在进行部署时采取手动方式,这样方便我们深入了解Ceph的底层.今天 ...

  2. 一道入门的java安全题

    [XCTF]Zhuanxv 收获 java题的一般流程 HQL注入 SQL注入 看题 目录扫描 dirsearch扫目录,发现list目录: 一个登录界面,本着尽量不写sql注入题目的原则(因为太菜了 ...

  3. JeecgBoot 框架升级至 Spring Boot3 的实战步骤

    JeecgBoot 框架升级 Spring Boot 3.1.5 步骤 JEECG官方推出SpringBoot3分支: https://github.com/jeecgboot/jeecg-boot/ ...

  4. Curator

  5. 【C#】【IO】【实例】接上一个统计的新功能

    先用Python来创建多层级文件夹: import os root_path = r"C:\Users\Desktop\文案整理\Practice" for item in ran ...

  6. ElasticSearch之cat templates API

    命令样例如下: curl -X GET "https://localhost:9200/_cat/templates?v=true&pretty" --cacert $ES ...

  7. Codeforce Round 916(div3)

    Codeforces Round 916(div3) [Problem - A - Codeforces]:Problemsolving Log A.题 直接看样例进行分析,发现每一次出现的字符代表着 ...

  8. 如何从零开始实现TDOA技术的 UWB 精确定位系统(2)

    这是一个系列文章<如何从零开始实现TDOA技术的 UWB 精确定位系统>第2部分. 重要提示(劝退说明): Q:做这个定位系统需要基础么?A:文章不是写给小白看的,需要有电子技术和软件编程 ...

  9. 我用 Laf 开发了一个非常好用的密码管理工具

    [KeePass 密码管理]是一款简单.安全简洁的账号密码管理工具,服务端使用 Laf 云开发,支持指纹验证.FaceID,N 重安全保障,可以随时随地记录我的账号和密码. 写这个小程序之前,在国内市 ...

  10. Docker本地部署Firefox火狐浏览器并远程访问

    Docker本地部署Firefox火狐浏览器并远程访问 Firefox是一款免费开源的网页浏览器,由Mozilla基金会开发和维护.它是第一个成功挑战微软Internet Explorer浏览器垄断地 ...