UVA 10128

1 篇文章 0 订阅

UVA10128

There is a queuewith N people. Every person has a different heigth. We can see P people, whenwe are looking from the beginning, and R people, when we are looking from theend. Its because they are having different height and they are covering eachother. How many different permutations of our queue has such a interestingfeature?

 Input

The input consistsof T test cases. The number of them (1 ≤ T ≤ 10000) is given on the first lineof the input file. Each test case begins with a line containing a singleinteger 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 thenumber of people, that we can see looking from the beginning. The secondinteger corresponds to the number of people, that we can see looking from theend.

 Output

For every test caseyour program has to determine one integer. Print how many permutations of Npeople we can see exactly P people from the beginning, and R people, when weare looking from the end.

Sample Input

3

10 4 4

11 3 1

3 1 2

Sample Output

90720

1026576

1

一.  题意分析

N个人排队,站在排头向后看可以看到P个人,站在排尾向前看可以看到R个人。给出N,P,R,求出所有的排队的可能情况。

二.  思路过程

假设现在队列由i-1个人变成了i个,由于谁后进到队列是无所谓的,不妨假设最矮的人是最后一个进入队列的,那么其所占的位置会有三种情况,第一种情况是站在队首,增加1个在前面能看到的人数,第二种情况是站在队尾,增加1个在后面能看到的人数,第三种情况是站在队伍中间,一共有i-2个位置可以站,但不会增加可见的人数。这样就能得到f[i][j][k]=f[i-1][j-1][k]+f[i][j][k-1]+(i-2)*f[i-1][j][k]

三.  代码

<span style="font-family:Courier New;font-size:18px;">#include <cstdio>
#include <string.h>
 
#define MAXD 20
 
int N, P, Q;
long long int f[MAXD][MAXD][MAXD];
 
void ans()
{
    int i, j, k;
    memset(f, 0, sizeof(f));
    f[1][1][1] = 1;
    for(i = 2; i <= 13; i ++)
        for(j = 1; j <= i; j ++)
            for(k = 1; k <= i; k ++)
                f[i][j][k] = f[i-1][j-1][k] + f[i-1][j][k-1] + (i-2) * f[i-1][j][k];
}
int main()
{
    int t;
    ans();
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d%d", &N, &P, &Q);
        printf("%lld\n", f[N][P][Q]);
    }
    return 0;
}</span>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值