UVA 题目10128 Queue(DP)
2015-11-18 11:03
615 查看
There is a queue with N people. Every person has a different heigth. We can see P people, when we
are looking from the beginning, and R people, when we are looking from the end. Its because they
are having different height and they are covering each other. How many different permutations of our
queue has such a interesting feature?
Input
The input consists of T test cases. The number of them (1 ≤ T ≤ 10000) is given on the first line of
the input file.
Each test case begins with a line containing a single integer number N that indicates the number
of people in a queue (1 ≤ N ≤ 13). Then follows line containing two integers. The first integer
corresponds to the number of people, that we can see looking from the beginning. The second integer
corresponds to the number of people, that we can see looking from the end.
Output
For every test case your program has to determine one integer. Print how many permutations of N
people we can see exactly P people from the beginning, and R people, when we are looking from the
end.
Sample Input
3
10 4 4
11 3 1
3 1 2
Sample Output
90720
1026576
1
题目大意:n个高低不同的人排队,从前边看有m个人,从后边能看到r个人。问有多少种站法
思路:dp[i][j][k]表示i个人,从前边看j个,从后边看k个的排法种类数,把最矮的放在前边j+1(谁都挡不住),放在最后边k+1,(谁都挡不住),放在中间任意一个位置,j,k不变,于是递推公式dp[i][j][k]=dp[i-1][j-1][k]+dp[i-1][j][k-1]+(i*2)*dp[i-1][j][k]
ac代码
are looking from the beginning, and R people, when we are looking from the end. Its because they
are having different height and they are covering each other. How many different permutations of our
queue has such a interesting feature?
Input
The input consists of T test cases. The number of them (1 ≤ T ≤ 10000) is given on the first line of
the input file.
Each test case begins with a line containing a single integer number N that indicates the number
of people in a queue (1 ≤ N ≤ 13). Then follows line containing two integers. The first integer
corresponds to the number of people, that we can see looking from the beginning. The second integer
corresponds to the number of people, that we can see looking from the end.
Output
For every test case your program has to determine one integer. Print how many permutations of N
people we can see exactly P people from the beginning, and R people, when we are looking from the
end.
Sample Input
3
10 4 4
11 3 1
3 1 2
Sample Output
90720
1026576
1
题目大意:n个高低不同的人排队,从前边看有m个人,从后边能看到r个人。问有多少种站法
思路:dp[i][j][k]表示i个人,从前边看j个,从后边看k个的排法种类数,把最矮的放在前边j+1(谁都挡不住),放在最后边k+1,(谁都挡不住),放在中间任意一个位置,j,k不变,于是递推公式dp[i][j][k]=dp[i-1][j-1][k]+dp[i-1][j][k-1]+(i*2)*dp[i-1][j][k]
ac代码
16452698 | 10128 | Queue | Accepted | C++ | 0.003 | 2015-11-18 02:59:23 |
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #define LL long long using namespace std; LL dp[22][22][22]; void fun() { int i,j,k; dp[1][1][1]=1; for(i=2;i<=13;i++) { for(j=1;j<=i;j++) { int r=i-j+1; for(k=1;k<=r;k++) { dp[i][j][k]=dp[i-1][j][k-1]+dp[i-1][j-1][k]+(i-2)*dp[i-1][j][k]; } } } } int main() { int t; scanf("%d",&t); fun(); while(t--) { int n,m,r; scanf("%d%d%d",&n,&m,&r); printf("%lld\n",dp [m][r]); } }
相关文章推荐
- UITableViewDelete 删除
- UITabView 添加
- Random_QuickSort
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout 还有drawRect方法
- 根据源码总结String,StringBuffer,StringBuider差异
- iOS小技巧:用runtime 解决UIButton 重复点击问题
- UIButton篇
- 【HDU5565 BestCoder Round 62 (div1)C】【STL or 二分答案 or 计数排序】Clarke and baton n个人减肥m次求最后异或值
- UItableViewController添加UITouch事件(添加点击事件)
- MySQL 报错 Truncated incorrect INTEGER value: ''
- iOS9 Storyboard unwind segue反回传递事件时机详细步骤
- EasyUI 之datagrid 使用 【DataGrid属性解释】
- openstack通过qemu-guest-agent在物理机上操作虚拟机
- webpack + babel + vue 环境设置
- UIViewController懒加载模式_易懂版
- UIAlertController的AlertView形式 加输入框 用法
- ArcGIS 10.2 Calculate Value(Data Management) 工具的使用
- Arduino系列教程之 – PWM的秘密
- 关于UIViewController添加UINavigationBar的详细实现方法
- Xcode:CUICatalog: Invalid asset name supplied: (null)