问题描述

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. Attach Files to Objects 将文件附加到对象

    In this lesson, you will learn how to attach file collections to business objects. For this purpose, ...

  2. java读取文本文件内容2

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/183 很久之前写了一篇Java读取文本文件内容,链接地址是 ...

  3. 《Python3 网络爬虫开发实战》学习资料

    <Python3 网络爬虫开发实战> 学习资料 百度网盘:https://pan.baidu.com/s/1PisddjC9e60TXlCFMgVjrQ

  4. docker可视化工具Portainer部署与汉化

    为了更好的观察Docker运行状态,我们采用Portainer工具进行可视化,下面是部署过程总结: 环境: Liunx:CentOS Linux release 7.6.1810 (Core) Doc ...

  5. SqlServer性能优化,查看CPU、内存占用大的会话及SQL语句

    1,查看CPU占用量最高的会话及SQL语句   select spid,cmd,cpu,physical_io,memusage, (select top 1 [text] from ::fn_get ...

  6. PostgreSQL中的onflict

    PostgreSQL 9.5 引入了一项新功能,UPSERT(insert on conflict do),当插入遇到约束错误时,直接返回,或者改为执行UPDATE. 1.不存在则插入,存在则更新 i ...

  7. 桶排序(C语言)

    #include <stdio.h> int main(void) { int arr[5]={2,5,1,3,3}; //定义需要排序的数组 int res[6]={0}; //初始化& ...

  8. 基于django的个人博客网站建立(六)

    基于django的个人博客网站建立(六) 前言 今天主要完成的是项目在腾讯云服务器上ubuntu16.04+django+mysql+uwsig+nginx的部署过程网站效果可点击这里访问 主要内容 ...

  9. pymysql用法,Python连接MySQL数据库

    Pymysql模块是专门用来操作mysql数据库的模块,使用前需要安装,安装指令:pip install pymysql 操作流程: 第一步:import pymysql 第二步:获取数据库的连接 , ...

  10. linux 常用命令及软件

    命令基于ubuntu 18.04 修改网卡配置 /etc/netplan/50-cloud-init.yaml #修改 netplan apply #应用修改 修改计算机名 sudo hostname ...