【POJ 2279】Mr. Young’s Picture Permutations【线性DP】
题目:
有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】的更多相关文章
- 轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- 【杨氏矩阵+勾长公式】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 2279] Mr. Young's Picture Permutations
[题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...
- 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从 ...
- bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式
2483: Pku2279 Mr. Young's Picture Permutations Time Limit: 1 Sec Memory Limit: 128 MB Description ...
- 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 dp
[题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...
- Mr. Young's Picture Permutations
Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增 ...
- 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)中的一个数 ...
随机推荐
- JavaWeb项目练习(学生选课管理系统)一
打算做一个选课管理系统,作为期末的复习. 上需求 2.1 页面要求 (1)系统可以通过浏览器直接访问:(1分) (2)各个功能页面整体风格统一:(2分) (3)首页为用户登录页面,管理员.教师.学生三 ...
- IDEA提示java_ 程序包org.apache.ibatis.session不存在
一.解决方案 1.问题原因: 这是因为配置Java的程序包这块出现了错误,同时可能你还没有设置让IDEA自动加载Jar包,才会报出这种错误的. 2.解决方案: 解决方式如下: File->Set ...
- 0x02.加密和编码
识别算法编码类型 看密文位数 看密文特征(数字.字母.大小写.符号等) 看当前密文存在的地方(web.数据库.操作系统等) 密码存储加密 md5:16位和32位由0-9和a-f组成的字符串 ,该加密方 ...
- maven使用指定的pom文件构建子模块
有条件的同学建议直接浏览原文: https://stackoverflow.com/questions/33396390/custom-pom-xml-filename-in-maven-multim ...
- xray+bp+echole+rad
安装证书 burp安装证书 开启burp suite,如下图所示下载证书后输入cacert.der即可 浏览器中上传证书,设置-->隐私和安全-->管理证书,一直下一步. xray安装证书 ...
- [ABC262E] Red and Blue Graph
Problem Statement You are given a simple undirected graph with $N$ vertices and $M$ edges. The verti ...
- 自定义一个简单的SpringBoot-Starter
1.创建一个简单的maven项目 2.导入相关依赖 <dependencies> <!--核心场景启动器,包含Spring的核心功能--> <dependency> ...
- Hystrix:Spring Cloud服务熔断与降级组件
Hystrix:Spring Cloud服务熔断与降级组件 问题总结 熔断器? Spring Cloud Hystrix? Hystrix服务降级? 全局降级方法? 解耦降级逻辑? Hystrix服务 ...
- 合宙esp32 c3 micro python 固件配置(基于thonny)
首先,本文档是已经配置过其他esp32后发现合宙的配置需要修改一些地方. 为了让新手们减少掉坑成本,故做了一个图文指导. 准备工作: 1.thonny安装(不讲,自己去查教程) 2.esp32c3 m ...
- STM32CubeMX教程6 TIM 通用定时器 - 生成PWM波
1.准备材料 开发板(STM32F407G-DISC1) ST-LINK/V2驱动 STM32CubeMX软件(Version 6.10.0) keil µVision5 IDE(MDK-Arm) 逻 ...