UVA 10128 - Queue(dp)
来源:互联网 发布:手机淘宝付款成功截图 编辑:程序博客网 时间:2024/05/14 04:08
Queue
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.It’s 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 Specification
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 consists of a line containing three integer numbers: N that indicates the number of people in a queue (1 <= N <= 13), and then two more integers. The first corresponds to the number of people, that we can see looking from the beginning, and the second corresponding to the number of people, that we can see looking from the end.
Output Specification
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
Output for the Sample Input
90720
1026576
1
题意:给定n个人,每个人高度不同,然后给定两个数字,代表从前面能看到的人和从后面看能看到的人(高的会把矮的挡住)
思路: dp[i][j][k] 代表 i个人,从前面看j个,从后面看k个, 那么每次插入最矮的人,如果插在队头,j + 1, 如果插在队尾k + 1,插在中间是没有影响的。中间的位置有i - 1个,由此一来可以推出状态转移方程dp[i][j][k] = dp[i - 1][j - 1][k] + dp[i - 1][j][k - 1] + dp[i - 1][j][k] * (i - 2);
代码:
#include <stdio.h>#include <string.h>const int N = 15;int t, n, q, h, dp[N][N][N];void init() { dp[1][1][1] = 1; for (int i = 2; i <= 13; i ++) {for (int j = 1; j <= 13; j ++) { for (int k = 1; k <= 13; k ++) {dp[i][j][k] += dp[i - 1][j - 1][k] + dp[i - 1][j][k - 1] + dp[i - 1][j][k] * (i - 2); }} }}int main() { init(); scanf("%d", &t); while (t --) {scanf("%d%d%d", &n, &q, &h);printf("%d\n", dp[n][q][h]); } return 0;}
- UVA 10128 - Queue(dp)
- UVa 10128 Queue (DP)
- uva 10128 - Queue(dp)
- uva 10128 Queue (dp)
- UVA 题目10128 Queue(DP)
- UVA - 10128 Queue (DP?DFS)
- UVA 10128 Queue
- UVA 10128 Queue
- UVA - 10128 Queue
- UVA-10128 Queue
- Uva 10128 - Queue 递推
- UVa Problem 10128 Queue (队伍)
- Team Queue(queue) - uva 540
- UVa 540 Team Queue
- uva 540 team queue
- Uva 540 Team Queue
- uva 540 - Team Queue
- UVa 540 - Team Queue
- cocos2d-x节点(CCActionCamera.h)API
- Jquery数组参考文章
- 黑马程序员_交通灯管理系统
- CODE 128: Median of Two Sorted Arrays
- ARM汇编写的流水灯,完全裸机(对于汇编学习,板子启动初始化认识帮助很大)
- UVA 10128 - Queue(dp)
- poj-1320 Street Number 佩尔方程
- hdu 2199Can you solve this equation?(牛顿迭代法)
- 听《神雕侠侣》
- [VirtualBox]虚拟机学习笔记-01
- 顺序队列类定义
- JS操作JSON总结
- 时间复杂度和空间复杂度详解
- MVC 只是一个思想,不是模式!!