【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)中的一个数 ...
随机推荐
- 超详细的Mysql锁 实战分析,你想知道的都在这里~
1.mysql回表查询 在这里提起主要是用于说明mysql数据和索引的结构,有助于理解后续加锁过程中的一些问题. mysql索引结构和表数据结构是相互独立的,根据索引查询,只能找到索引列和主键聚簇索引 ...
- STA分析-复制
1 静态时序分析(Static Timing Analysis)静态时序分析(Static Timing Analysis):静态执行对于数字设计时序的分析,不依赖于施加在输入端口上的激励,验证设计是 ...
- [python][图像切割]给定手写数字图片完成数字切割
import torch import torch.nn as nn from torchvision import transforms from PIL import Image, ImageOp ...
- 【scikit-learn基础】--『预处理』之 标准化
数据的预处理是数据分析,或者机器学习训练前的重要步骤.通过数据预处理,可以 提高数据质量,处理数据的缺失值.异常值和重复值等问题,增加数据的准确性和可靠性 整合不同数据,数据的来源和结构可能多种多样, ...
- JS对后端响应的long类型数据处理精度丢失问题
1.数据库的数据 2.前端拿到的数据 前端帮我们进行四舍五入了,这并不是我想要的 3.解决办法 把后端响应的数据long类型转成string类型,可以使用Stream流的方式或者for循环的方式,对响 ...
- flask请求钩子(就是django的中间件)
flask中的请求钩子就是域django的中间件类似,作用都是用于在请求前.后.响应前.后进行一些hook操作. 请求钩子装饰器 @app.before_request # 请求前会调用,一般可以用来 ...
- lca(数链剖分)板子
#include<bits/stdc++.h> #define endl '\n' #define int long long using namespace std; const int ...
- [转]NLog学习笔记
配置文件 NLog所有的配置信息都可以写到一个单独的xml文件中,也可以在程序代码中进行配置. 配置文件位置 启动的时候,NLog会试图查找配置文件完成自动配置,查找的文件依次如下(找到配置信息则结束 ...
- 关于开放签CA数字证书设计的思考
这几天在调研CA数字证书以及思考如何在产品中集成使用CA数字证书,主要的目的和方向有以下几点: 有法律效力的电子文件的签署需要使用权威的证书颁发机构(CA)颁发的数字证书: 我们希望找到更便宜的证书方 ...
- Ubuntu 下建立 eclipse 启动图标,解决ADT没有菜单栏问题(转载)
原文地址 怎么在这应用程序里边建立图标$sudo gedit /usr/share/applications/Eclipse.desktop输入以下代码 [Desktop Entry]Name=Ecl ...