bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式
2483: Pku2279 Mr. Young's Picture Permutations
Time Limit: 1 Sec Memory Limit: 128 MB
Description
X X X X X
X X X
X X X
X
In addition, Mr. Young wants the students in each row arranged so that heights decrease from left to right. Also, student heights should decrease from the back to the front. Thinking about it, Mr. Young sees that for the 12-student example, there are at least two ways to arrange the students (with 1 as the tallest etc.):
1 2 3 4 5 1 5 8 11 12
6 7 8 2 6 9
9 10 11 3 7 10
12 4
Mr. Young wonders how many different arrangements of the students there might be for a given arrangement of rows. He tries counting by hand starting with rows of 3, 2 and 1 and counts 16 arrangements:
123 123 124 124 125 125 126 126 134 134 135 135 136 136 145 146
45 46 35 36 34 36 34 35 25 26 24 26 24 25 26 25
6 5 6 5 6 4 5 4 6 5 6 4 5 4 3 3
Mr. Young sees that counting by hand is not going to be very effective for any reasonable number of students so he asks you to help out by writing a computer program to determine the number of different arrangements of students for a given set of rows.
杨先生要给他的学生们拍照片。首先,站队状况是确定的,若第i行站了a[i]个人,则有a[1] ≥ a[2] ≥ ... ≥ a[n],所有的行都是靠左对齐的。并且,在同一行和同一列里面,从左到右或者从上到下身高都是递减的。现在所有学生的身高都不相同,学生数不超过30个,行数不超过5。你需要求出所有可能的排队方法的总数。
Input
Output
Sample Input
30
5
1 1 1 1 1
3
3 2 1
4
5 3 3 1
5
6 5 4 3 2
2
15 15
0
Sample Output
1
16
4158
141892608
9694845
HINT
先介绍一下什么是杨氏矩阵(Young tableau)//允许我转载一下 QwQ 出处:https://www.zhihu.com/question/52335435/answer/130097881
- 矩阵里同一行的元素,左边的元素小于右边的元素。
- 矩阵里同一列的元素,上边的元素小于下边的元素。
而问题中所求的是排列,可以双射到它的逆排列,统计逆排列的个数,具体来说,就是求在排列里的排名,从而转化为将
到
填充到矩阵中,问有多少种方法满足杨氏矩阵的限制。
固定矩阵形态,求有多少种本质不同的杨氏矩阵,这个问题是非常经典的,可以使用钩子公式(Hook length formula)求解。
定义表示矩阵里满足
或
的
位置个数,则本质不同的杨氏矩阵个数是
。
那么对于这个问题,满足条件的排列数就是,是
的。
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,a[],sum,ji[];
bool mp[][];
ll ans=;
ll ksm(ll a,int b)
{
ll s=;
for(;b;b>>=,a*=a) if(b&) s*=a;
return s;
}
int main()
{
int i,j,h,k;
while(n=read())
{
ans=;sum=;
memset(ji,,sizeof(ji));
memset(mp,,sizeof(mp));
for(i=;i<=n;i++)
{
a[i]=read();sum+=a[i];
for(j=;j<=a[i];j++) mp[i][j]=;
}
for(i=;i<=sum;i++)
{
int tp=i;
for(j=;j<=tp;j++)
while(tp%j==) tp/=j,ji[j]++;
}
for(i=;i<=n;i++)
{
for(j=;j<=a[i];j++)
{
h=a[i]-j;
for(k=i;k<=n;k++) if(mp[k][j]) h++;
int tp=h;
for(k=;k<=tp;k++)
while(tp%k==) tp/=k,ji[k]--;
}
}
for(i=;i<=;i++) ans*=ksm((ll)i,ji[i]);
printf("%lld\n",ans);
}
return ;
}
bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式的更多相关文章
- 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:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- Mr. Young's Picture Permutations
Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增 ...
- 【杨氏矩阵+勾长公式】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)中的一个数 ...
随机推荐
- Paramiko使用
1.下载安装 pycrypto-2.6.1.tar.gz (apt-get install python-dev) 解压,进入,python setup.py build[编译],python set ...
- Java错误提示:Syntax error, insert "}" to complete Block
从网上复制了一段java代码到Eclipse里面,调整了一下格式,把Eclipse提示的明显有问题的地方,主要是空格,删掉了,但还是在最后一个分号那里提示“Syntax error, insert & ...
- hibernate CasCade deleted object ould be re-saved by cascade
这个问题个人认为看你用的那种方式,如果是注解式的 比如: @ManyToMany(cascade={CascadeType.MERGE,CascadeType.REFRESH,CascadeType. ...
- sqlmap tamper编写
#!/usr/bin/env python """ Copyright (c) 2006-2017 sqlmap developers (http://sqlmap.or ...
- 巅峰极客CTF writeup[上]
经验教训 1.CTF不比实战,最好不要死磕.死磕就输了.我就是死磕在缓存文件死的.真的惭愧: 2.对于flag的位置不要太局限于web目录下,如果是命令执行直接上find / -name flag*: ...
- SQLite3 使用教学
source: SQL中文站:http://www.sqlite.com.cn/MySqlite/4/378.Html OS X自从10.4后把SQLite这套相当出名的数据库软件,放进了作业系统工具 ...
- 百度地图js lite api 支持点聚合
百度地图lite api 是专门为h5 绘制海量点设计的,但是偏偏忽略掉了点聚合的需求,所以需要自己动手,做一次二次改造. 我们知道点聚合需要引入开源库: MarkerClusterer: http ...
- 制作自动化系统安装U盘
1.挂载CentOS6.6镜像 [root@test88 ~]# mkdir /application/tools -p [root@test88 ~]# cd /application/tools/ ...
- GitHub vs GitLab:它们有什么区别?
查看原文GitLab vs. GitHub: How Are They Different? 两者都是基于web的Git repositories(仓库),拥有流水线型的web开发流程,它们为开发团队 ...
- 系统日志查看logrotate 工具
logrotate是作为linux系统日志的管理工具存在.他可以轮换,压缩,邮件系统日志文件. 默认的logrotate被加入cron的/etc/cron.daily中作为每日任务执行./etc/lo ...