问题描述

LG-SP


题解

发现\(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 高维动态规划的更多相关文章

  1. SP15637 GNYR04H - Mr Youngs Picture Permutations[DP]

    题目来源:POJ:http://poj.org/problem?id=2279 SPOJ:https://www.spoj.com/problems/GNYR04H/ 题意翻译 题目描述 杨先生希望为 ...

  2. $SP15637\ GNYR04H\ -\ Mr\ Youngs\ Picture\ Permutations$

    传送门 Description 杨先生希望为他的班级拍照.学生将排成一行,每行不超过后面的行,并且行的左端对齐.例如,可以安排12名学生排列(从后到前)5,3,3和1名学生. X X X X X X ...

  3. POJ2279 Mr Young's Picture Permutations

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

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

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

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

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

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

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

  7. Mr. Young's Picture Permutations

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

  8. 【CF285E】Positions in Permutations(动态规划,容斥)

    [CF285E]Positions in Permutations(动态规划,容斥) 题面 CF 洛谷 题解 首先发现恰好很不好算,所以转成至少,这样子只需要确定完一部分数之后剩下随意补. 然后套一个 ...

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

随机推荐

  1. 2.Ansible Playbook剧本

    1.playbook?playbook翻译过来就是"剧本",那playbook组成如下 play: 定义的是主机的角色 task: 定义的是具体执行的任务 playbook: 由一 ...

  2. 松软科技web课堂:JavaScript Math 对象

    JavaScript Math 对象允许您对数字执行数学任务. 实例 Math.PI; // 返回 3.141592653589793 Math.round() Math.round(x) 的返回值是 ...

  3. Vue初始化过程

    用vue也有一两年了,始终对vue一知半解,不怎么了解内部的执行过程,最近在看vue源码,还是不少收获的,其中不乏浏览器事件轮询机制.闭包.设计模式等,还是非常值得一读.本篇简要记录下vue的初始化过 ...

  4. MTK Recovery 模式横屏修改(适用于6.0 + 8.1)

    修改前 修改后 6.0 Recovery 模式横屏修改方法 修改相关文件 bootable\recovery\minui\Android.mk bootable\recovery\minui\mt_g ...

  5. C编程小结1

    1. ‘\0’表示字符串结束符 2. 变量之间互相赋值一定要考虑他们的数据类型,要强制转换匹配上了或者进行一些处理才能赋值,同时读程序的时候也要注意这一点,否则可能看不懂.如: sData[0]=wD ...

  6. 字符串 string方法

    字符串 name = 'ab c dd' i = name.find('a', 1, 3) # 找到返回对应下标 找不到返回-1 print(i) j = name.rfind('d') # 寻找对应 ...

  7. bayaim_Centos7.6_mysql源码5.7-多my.cnf_20190424.txt

    用户名/密码mysql/mysql 一.安装mysql: 位置位于 /data/mysql 如果遇到依赖,无法删除,使用 rpm -e --nodeps <包的名字> 不检查依赖,直接删除 ...

  8. s3c2440裸机-代码重定位(1.重定位的引入,为什么要代码重定位)

    1.重定位的引入(为什么要代码重定位) 我们知道s3c2440的cpu从0地址开始取指令执行,当从nor启动时,0地址对应nor,nor可以像内存一样读,但不能像内存一样写.我们能够从nor上取指令执 ...

  9. 6 Ubuntu软件安装

      6 软件安装¶ 6.1 通过apt 安装/卸载软件¶ apt是Advanced Packaging Tool,是Linux下的一款安装包管理工具 可以在终端中方便的安装/卸载/更新软件包 # 1. ...

  10. November 10th, Week 45th, Sunday, 2019

    Perfection has no place in love. 爱从不完美. Perfection has no place in love, and we should always try to ...