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[a+1][b][c][d][e]+=f[a][b][c][d][e]
\]

\[f[a][b+1][c][d][e]+=f[a][b][c][d][e]
\]

\[f[a][b][c+1][d][e]+=f[a][b][c][d][e]
\]

\[f[a][b][c][d+1][e]+=f[a][b][c][d][e]
\]

\[f[a][b][c][d][e+1]+=f[a][b][c][d][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的更多相关文章

  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   ...

  2. POJ2279 Mr Young's Picture Permutations

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

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

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

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

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

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

  6. 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 ...

  7. [POJ 2279] Mr. Young's Picture Permutations

    [题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...

  8. 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从 ...

  9. poj2279 Mr. Young's Picture Permutations[勾长公式 or 线性DP]

    若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数 ...

随机推荐

  1. JVM内核-原理、诊断与优化学习笔记(二):JVM运行机制

    文章目录 JVM启动流程 PC寄存器 方法区 保存装载的类信息 通常和永久区(Perm)关联在一起 Java堆 Java栈 Java栈 – 局部变量表 ** 包含参数和局部变量 ** Java栈 – ...

  2. spark-submit 应用程序第三方jar文件

    第一种方式:打包到jar应用程序 操作:将第三方jar文件打包到最终形成的spark应用程序jar文件中 应用场景:第三方jar文件比较小,应用的地方比较少 第二种方式:spark-submit 参数 ...

  3. sklearn参数优化

    学习器模型中一般有两个参数:一类参数可以从数据中学习估计得到,还有一类参数无法从数据中估计,只能靠人的经验进行指定,后一类参数就叫超参数 比如,支持向量机里的C,Kernel,gama,朴素贝叶斯里的 ...

  4. uoj139 【UER #4】被删除的黑白树

    题目 不难发现有一个暴力\(dp\) 设\(dp[x][l]\)表示\(x\)点子树内所有叶子节点到\(x\)的路径上都有\(l\)和黑点时最多能染多个黑点 转移就是 \[dp[x][l]=\max( ...

  5. Number Sequence /// oj21456

    题目大意: 有一组规律数 the first 80 digits of the sequence are as follows: 1 12 123 1234 12345 123456 1234567 ...

  6. bias、variance与拟合之间的关系

    Error = Bias^2 + Variance+Noise 误差的原因: 1.Bias反映的是模型在样本上的输出与真实值之间的误差,即模型本身的精准度,即算法本身的拟合能力. 2.Variance ...

  7. 前端常用的库和实用技术之JavaScript多线程

    多线程概念: 多线程是指从软件或硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在 同一时间执行多于一个线程,进而提升整理处理性能.具有这种能力的系统包括对称多处理机,多核心 ...

  8. Altera设置Virtual Pin

    1,GUI方式 大家都知道的,assignment editor –> category –> logic options –> to –> virtual pin –> ...

  9. Python: 生成器与迭代 generators and iteration

    https://eastlakeside.gitbooks.io/interpy-zh/content/Generators/ 文章不是非常好 1,三个概念 可迭代对象 iterable, 迭代器 i ...

  10. 解析Mybatis入门第二天

    入门第二天 目的:使用Mybatis对数据库中的数据进行简单的操作.例如:增.删.改.查. 前言:同样是使用idea创建一个普通的maven工程(如何创建一个普通的Maven工程可以参考入门第一天的详 ...