UVA10128 Queue递推
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10128 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. 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
问题链接:UVA10128 Queue
问题简述:给定整数n、p和r,表示有n个人排队,他们高低不同,从前面看可以看到p个人,从后面看可以看到r个人。问这种队列有多少种?
问题分析:递推问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10128 Queue */
#include <bits/stdc++.h>
using namespace std;
const int N = 13;
long long dp[N + 1][N + 1][N + 1];
int main()
{
// Init
memset(dp, 0, sizeof dp);
dp[1][1][1] = 1;
for (int n = 2; n <= N; n++)
for (int p = 1; p <= N; p++)
for (int r = 1; r <= N; r++)
dp[n][p][r] = (n - 2) * dp[n - 1][p][r] + dp[n - 1][p - 1][r] + dp[n - 1][p][r - 1];
int t, n, p, r;
scanf("%d", &t);
while (t--) {
scanf("%d%d%d", &n, &p, &r);
printf("%lld\\n", dp[n][p][r]);
}
return 0;
}
以上是关于UVA10128 Queue递推的主要内容,如果未能解决你的问题,请参考以下文章