SP15637 Mr Youngs Picture Permutations 高维动态规划
问题描述
题解
发现\(n,k\)都非常小,尤其是\(k,k\le 5\),于是直接开\(5\)维进行\(\mathrm{DP}\)
用记忆化搜索实现。
\(\mathrm{Code}\)
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <typename Tp>
void read(Tp &x){
x=0;char ch=1;int fh;
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-'){
fh=-1;ch=getchar();
}
else fh=1;
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+ch-'0';
ch=getchar();
}
x*=fh;
}
int opt[31][31][31][31][31];
int a[7],n;
int dp(int a,int b,int c,int d,int e){
if(!a&&!b&&!c&&!d&&!e) return opt[a][b][c][d][e]=1;
int &k=opt[a][b][c][d][e];
if(k) return k;
if(a>b) k+=dp(a-1,b,c,d,e);
if(b>c) k+=dp(a,b-1,c,d,e);
if(c>d) k+=dp(a,b,c-1,d,e);
if(d>e) k+=dp(a,b,c,d-1,e);
if(e>0) k+=dp(a,b,c,d,e-1);
return k;
}
signed main(){
while(1){
read(n);
memset(opt,0,sizeof(opt));
if(!n) return 0;
for(int i=1;i<=n;i++) read(a[i]);
for(int i=n+1;i<=5;i++) a[i]=0;
printf("%lld\n",dp(a[1],a[2],a[3],a[4],a[5]));
}
return 0;
}
SP15637 Mr Youngs Picture Permutations 高维动态规划的更多相关文章
- SP15637 GNYR04H - Mr Youngs Picture Permutations[DP]
题目来源:POJ:http://poj.org/problem?id=2279 SPOJ:https://www.spoj.com/problems/GNYR04H/ 题意翻译 题目描述 杨先生希望为 ...
- $SP15637\ GNYR04H\ -\ Mr\ Youngs\ Picture\ Permutations$
传送门 Description 杨先生希望为他的班级拍照.学生将排成一行,每行不超过后面的行,并且行的左端对齐.例如,可以安排12名学生排列(从后到前)5,3,3和1名学生. X X X X X X ...
- POJ2279 Mr Young's Picture Permutations
POJ2279 Mr Young's Picture Permutations 描述: 有N个学生合影,站成左对齐的k排,每行分别有N1,N2…NK个人,第一排站最后,第k排站之前.学生身高依次是1… ...
- 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 dp
[题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...
- 轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- Mr. Young's Picture Permutations
Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增 ...
- 【CF285E】Positions in Permutations(动态规划,容斥)
[CF285E]Positions in Permutations(动态规划,容斥) 题面 CF 洛谷 题解 首先发现恰好很不好算,所以转成至少,这样子只需要确定完一部分数之后剩下随意补. 然后套一个 ...
- 【杨氏矩阵+勾长公式】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 ...
随机推荐
- tesseract-OCR + pytesseract安装
1. tesseract-OCR下载安装 地址:https://digi.bib.uni-mannheim.de/tesseract/ 选择一个版本下载,下载完成点击**.exe进行安装,若无其他需求 ...
- 简约清新立体商务年终工作总结汇报动态PPT模板
模版来源:http://ppt.dede58.com/gongzuohuibao/26682.html
- Redis未授权访问利用
转载:https://www.cnblogs.com/-qing-/p/10978912.html 0x01 kali安装redis 下载 wget http://download.redis.io/ ...
- Android五大布局详解——LinearLayout(线性布局)
Android五大布局 本篇开始介绍Android的五大布局的知识,一个丰富的界面显示总是要有众多的控件来组成的,那么怎样才能让这些控件能够按你的想法进行摆放,从而自定义你所想要的用户界面呢?这就牵涉 ...
- Spring整合JMS消息中间件
1. 点对点模式 1.1消息生产者 (1)创建工程springjms_producer,在POM文件中引入SpringJms .activeMQ以及单元测试相关依赖 (2)在src/main/reso ...
- SQL Server之批量清理数据库的死锁
DECLARE killspid CURSOR FOR (SELECT CONVERT(VARCHAR(100), request_session_id) FROM sys.dm_tran_l ...
- COUNT(*)、COUNT(主键)、COUNT(1)
MyISAM引擎,记录数是结构的一部分,已存cache在内存中; InnoDB引擎,需要重新计算,id是主键的话,会加快扫描速度: 所以select count(*) MyISAM完胜! MyISA ...
- 人生第一次研读MFC截图工具的笔记心得
截图工具: 其中用到了动态链接库DLL技术(Dynamic Link Library)技术,键盘钩子技术,光标捕获技术,类橡皮类CRectTracker 头文件:后缀名为.cpp,主要是定义和声明之类 ...
- 2.华为路由交换技术_TCP/IP参考模型
1.应用层 2.传输层(主机到主机层) 3.网络层(IPV4) ARP协议:地址解析协议 原理:源终端A想要发送信息给目的终端B,已知B的IP地址,需要获取B的MAC地址.首先它会在局域网广播,一般情 ...
- Elasticsearch 6.x版本全文检索学习之聚合分析入门
1.什么是聚合分析? 答:聚合分析,英文为Aggregation,是es除搜索功能外提供的针对es数据做统计分析的功能.特点如下所示: a.功能丰富,提供Bucket.Metric.Pipeline等 ...