问题描述

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. 《C#并发编程经典实例》学习笔记—3.1 数据的并行处理

    问题 有一批数据,需要对每个元素进行相同的操作.该操作是计算密集型的,需要耗费一定的时间. 解决方案 常见的操作可以粗略分为 计算密集型操作 和 IO密集型操作.计算密集型操作主要是依赖于CPU计算, ...

  2. bootstrap-table 常用总结-1

    两种表格工具,今天都用到了,一种是我前几篇写到过的jqgrid,(传送门)另一个就是bootstrap-table了.用过之后会发现,两种表格的方式大同小异,但是为什么这次要换成bootstrap-t ...

  3. ES6知识点脑图

    点击左键 => 拖拽图片 => 新标签页查看图片 => 放大拖拽查阅

  4. js-08-数组学习

    一.数组语法格式 var name=[item1,item2,......] 二.数组的声明创建 var arr=new Aarray( ) //声明一个空数组对象 var arr=new Array ...

  5. 一个神奇的HTML标签-----marquee

    今天无意中发现了一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 语法:<marquee>...</marqu ...

  6. ES6-map数据结构,增加、删除、查找 方法(set get has delete clear ) 属性:size

    map数据结构: 本质上是键值对的集合,类似集合: 可以遍历,方法很多,可以跟各种数据格式转换. let json = { name:'ananiah', age:'18' } //效率低 需要遍历j ...

  7. leaflet-webpack 入门开发系列五地图卷帘(附源码下载)

    前言 leaflet-webpack 入门开发系列环境知识点了解: node 安装包下载webpack 打包管理工具需要依赖 node 环境,所以 node 安装包必须安装,上面链接是官网下载地址 w ...

  8. spring为类的静态属性实现注入

    我们知道,正常情况下,spring的一个bean要依赖其他资源,如properties或其他bean,直接利用@Value或@Autowired就可以了.这两个注解就相当于spring applica ...

  9. 数据库三,exec内置函数

    数据库三,exec内置函数 一.数据库查询与执行顺序 必备知识 查询语句的基本操作 - select - from - where - group by - having - distinct - o ...

  10. MySQL数据库~~~~pymysql 连接 MySQL的客户端

    import pymysql conn = pymysql.connect( host = '127.0.0.1', # 主机 port = 3306, # 端口号 user = 'root', # ...