【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)中的一个数 ...
随机推荐
- Kotlin协程系列(一)
一.协程的定义 最近看了一本有关kotlin协程的书籍,对协程又有了不一样的了解,所以准备写一个关于kotlin协程系列的文章. 言归正传,我们在学习一个新东西的时候,如果连这个东西"是什么 ...
- MongoDB 6.0 单实例基于用户角色实现授权登录
现代数据库系统能够存储和处理大量数据.因此,由任何一个用户单独负责处理与管理数据库相关的所有活动的情况相对较少.通常,不同的数据库用户需要对数据库的某些部分具有不同级别的访问权限:某些用户可能只需要读 ...
- 从0到1,手把手带你开发截图工具ScreenCap------001实现基本的截图功能
ScreenCap---Version:001 说明 从0到1,手把手带你开发windows端的截屏软件ScreenCap 当前版本:ScreenCap---001 支持全屏截图 支持鼠标拖动截图区域 ...
- [ABC317G] Rearranging
Problem Statement There is a grid with $N$ rows and $M$ columns. The square at the $i$-th row from t ...
- 实现 Raft 协议
文章地址 简介 Raft 是一个分布式共识算法,用于保证所有机器对一件事达成一个看法.本文用于记录实现 Raft 选举和日志复制的代码细节. 选举 节点启动时首先是跟随者状态,如果到达选举超时时间就尝 ...
- 数字孪生结合GIS能够为城市灾害预防工作提供什么帮助?
数字孪生技术结合GIS(地理信息系统)在城市灾害预防工作中发挥着重要的作用,为城市的安全和可持续发展提供了关键帮助.数字孪生是一种将现实世界与数字虚拟世界相结合的技术,可以帮助城市规划者和管理者更好地 ...
- 37. 干货系列从零用Rust编写负载均衡及代理,负载均衡中try_files实现
wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,四层TCP/UDP转发,七层负载均衡,内网穿透,后续将实现websocket代 ...
- Go 语言为什么很少使用数组?
大家好,我是 frank,「Golang 语言开发栈」公众号作者. 01 介绍 在 Go 语言中,数组是一块连续的内存,数组不可以扩容,数组在作为参数传递时,属于值传递. 数组的长度和类型共同决定数组 ...
- 【scikit-learn基础】--『监督学习』之 决策树回归
决策树算法是一种既可以用于分类,也可以用于回归的算法. 决策树回归是通过对输入特征的不断划分来建立一棵决策树,每一步划分都基于当前数据集的最优划分特征.它的目标是最小化总体误差或最大化预测精度,其构建 ...
- 通过数字证书对PDF电子文件进行数字签名/盖章
以下代码详细说明如何使用数字证书对PDF电子文件进行数字签名/盖章.PDF文件签署主要传递PDF文件,数字证书信息,签章图片3个信息.代码中需要的文件.数字证书.签章图片可访问开放签电子签章开源系统详 ...