Mr. Young's Picture Permutations
Mr. Young's Picture Permutations
给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增的方案数,\(n\leq 30,k\leq 5\)。
解
事实上,注意到k很小,我们就可以暴力状态了,而要表现单调递增,故维护一个从左至右边矮的阶梯。
以有5列为例,设\(f[a][b][c][d][e]\)表示第1列已经填的数字高度为a,第二列高度为b,...,第5列的高度为e的,现在填到数字\(a+b+c+d+e\)方案数,并保证转移时\(a\geq b\geq c\geq d\geq e\),于是当一个新的数字填的时候一定比所有的数字都要大,也不会有比它小的数字使其非法,故满足了题意。
有因为逆转移无用状态枚举过多,考虑顺转移,因此有
\]
\]
\]
\]
\]
边界:\(f[0][0][0][0][0]=1\),其余为0
答案:\(f[n_1][n_2][n_3][n_4][n_5]\)
参考代码:
阶段转移
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define ll long long
using namespace std;
ll len[31],dp[31][16][11][8][7];
il void read(ll&);
int main(){
ll k,n;
while(read(k),k){
memset(len,0,sizeof(len));
memset(dp,0,sizeof(dp)),dp[0][0][0][0][0]=1;
for(ri ll i(1);i<=k;++i)read(len[i]);
for(ri ll a,b,c,d,e(0);e<=len[5];++e)
for(d=e;d<=len[4];++d)
for(c=d;c<=len[3];++c)
for(b=c;b<=len[2];++b)
for(a=b;a<=len[1];++a){
if(a<len[1])dp[a+1][b][c][d][e]+=dp[a][b][c][d][e];
if(b<len[2])dp[a][b+1][c][d][e]+=dp[a][b][c][d][e];
if(c<len[3])dp[a][b][c+1][d][e]+=dp[a][b][c][d][e];
if(d<len[4])dp[a][b][c][d+1][e]+=dp[a][b][c][d][e];
if(e<len[5])dp[a][b][c][d][e+1]+=dp[a][b][c][d][e];
}
printf("%lld\n",dp[len[1]][len[2]][len[3]][len[4]][len[5]]);
}
return 0;
}
il void read(ll &x){
x&=0;ri char c;while(c=getchar(),c<'0'||c>'9');
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}
dfs
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define ll long long
using namespace std;
int len[6];
ll dp[31][16][11][8][7];
il void read(int&);
ll dfs(int,int,int,int,int);
int main(){
int k;while(read(k),k){
memset(len,0,sizeof(len));
memset(dp,0,sizeof(dp)),dp[0][0][0][0][0]=1;
for(ri int i(1);i<=k;++i)read(len[i]);
printf("%lld\n",dfs(len[1],len[2],len[3],len[4],len[5]));
}
return 0;
}
ll dfs(int a,int b,int c,int d,int e){
if(a<0||b<0||c<0||d<0||e<0)return 0;
ll &opt=dp[a][b][c][d][e];if(opt)return opt;
opt=dfs(a,b,c,d,e-1);
if(d>e)opt+=dfs(a,b,c,d-1,e);
if(c>d)opt+=dfs(a,b,c-1,d,e);
if(b>c)opt+=dfs(a,b-1,c,d,e);
if(a>b)opt+=dfs(a-1,b,c,d,e);
return opt;
}
il void read(int &x){
x&=0;ri char c;while(c=getchar(),c<'0'||c>'9');
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}
Mr. Young's Picture Permutations的更多相关文章
- 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)\)代表每一行多少人,判断边界就能 ...
- 轮廓线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 ...
- 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 ...
- [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从 ...
- poj2279 Mr. Young's Picture Permutations[勾长公式 or 线性DP]
若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数 ...
随机推荐
- 其它课程中的python---2、NumPy模块
其它课程中的python---2.NumPy模块 一.总结 一句话总结: numpy在数组计算方面又快又方便 1.NumPy中的ndarray是一个多维数组对象,该对象由哪两部分组成? -实际的数据 ...
- CApiHook__Api钩子类
见过网上有很多ApiHook的类,但是都不尽入人意,要么就是写的不够好不够完善,要么就是跑不起来. 用别人写的代码总是有种不安心,所以自己就花了一晚上写了CApiHook类.已经尽量确保自己写的类是非 ...
- JavaScript网页特效5则
动态字幕 代码:在需要处加入 < marquee onmouseover=this.stop() onmouseout=this.start()>欢迎访问JavaScript教程网 特点: ...
- IDEA @Autowired dao大红波浪线
SptingBoot+Mybatis开发通常在dao层的注解是@Mapper 这样每次在ServiceImpl层加注解@Autowired时,注入的dao总是波浪线烦人,其实并没有错,只是idea你太 ...
- Spark DataFrame中的join使用说明
spark sql 中join的类型 Spark DataFrame中join与SQL很像,都有inner join, left join, right join, full join; 类型 说明 ...
- 学习k8s的经验
最近在学k8s,总结一下安装k8s的坑. 1.晚上关于k8s的学习资料很多,多不如精,这个博客很好,https://blog.csdn.net/sinat_35930259/article/categ ...
- SparkStreaming整合Flume的pull方式之启动报错解决方案
Flume配置文件: simple-agent.sources = netcat-source simple-agent.sinks = spark-sink simple-agent.channel ...
- IK的整个分词处理过程
首先,介绍一下IK的整个分词处理过程: 1. Lucene的分词基类是Analyzer,所以IK提供了Analyzer的一个实现类IKAnalyzer.首先,我们要实例化一个IKAnalyzer,它有 ...
- 常见PID里面的像素大小
因为tensorflow/models里faster R-cnn目前识别的好像是按照像素比上图片大小来识别的,所以在这里统计一下各个元件的像素大小的范围 DCS:70~200
- xampp只允许本地访问,禁止远程访问
远程访问phpmyadmin的时候出现错误 New XAMPP security concept: Access to the requested object is only available f ...