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


这道题是从大神的博客里面看到的解法,就可以想象自己正在向队列中插入人数,有三种方式,一种是放在最左边,一种是放在最右边,还有一种是

放在中间,也就是都看不到的地方,我认为这种思想就是像递归,用一个三维的数组,i表示,之前已经放好的人数,j表示从前面可以看到的人数,而

k表示从后面可以看到的人数,那么假设前面一种的情况是已经确定了的,那么此时的情况也就建立在之前情况下解决,而不用完全去想清楚之前的那种

情况是什么,这就是我的理解


#include<iostream>
#include<cstring>
using namespace std;

int qun[15][15][15];
int main()
{
    int times;
    cin>>times;
    while(times--)
    {
        memset(qun,0,sizeof(qun));
        int n,p,r;
        cin>>n>>p>>r;
        qun[1][1][1] = 1;
        for(int i = 2;i<=n;i++)
            for(int j = 1;j<=i;j++)
            for(int k = 1;k<=i;k++)
            qun[i][j][k] = qun[i-1][j-1][k] + qun[i-1][j][k-1] + (i-2)*qun[i-1][j][k];
        cout<<qun[n][p][r]<<endl;
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值