问题描述:n(1<=n<=13)个身高均不相等的人站成一排,从左向右看能看见L个人,从右向左看能看见R个人,问这个队列有多少种排法?

问题分析:  1.n个人的身高可设为1~n,

       2.设dp[k][i][j]中,k代表当前有k个人的队列,i代表从左边看能看见的人数,j代表从右边看能看到的人数

       3.由于谁先进队列,谁后进队列无所谓,我们从最高的人开始排起,保证每次新加入队列的人都是队列里边最矮的一个。

       4.若将新加的人放在最左边,则dp[k][i][j] += dp[k-1][i-1][j];

          若将新加的人放在最右边,则dp[k][i][j] += dp[k-1][i][j-1];

          若将新加入的人放在中间的任意地方,则dp[k][i][j] += dp[k-1][i][j]*(k-2);

       所以状态转移方程为:dp[k][i][j] = dp[k-1][i-1][j] + dp[k-1][i][j-1] + dp[k-1][i][j]*(k-2);

例题链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1069

例题:UVa 10128

10128 - Queue

Time limit: 3.000 seconds

  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 rst 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

代码:

 #include "stdio.h"
#include "string.h"
#define N 15
int dp[N][N][N]; int main()
{
int T;
int n,L,R;
int i,j,k;
scanf("%d",&T);
memset(dp,,sizeof(dp));
dp[][][] = ;
for(k=; k<N; k++)
{
for(j=; j<=k; j++)
{
for(i=; i<=k-j+; i++)
dp[k][i][j] = dp[k-][i][j]*(k-) + dp[k-][i-][j] + dp[k-][i][j-];
}
}
while(T--)
{
scanf("%d %d %d",&n,&L,&R);
printf("%d\n",dp[n][L][R]);
}
}

08_Queue(队列UVa 10128)的更多相关文章

  1. uva 10128

    动归 转移方程 :dp(i, j, k) = dp(i – 1, j, k) * (i – 2) + dp(i – 1, j – 1, k) + dp(i – 1, j, k – 1) i表示此时排第 ...

  2. UVa 12100打印队列(队列)

    原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. UVA.540 Team Queue (队列)

    UVA.540 Team Queue (队列) 题意分析 有t个团队正在排队,每次来一个新人的时候,他可以插入到他最后一个队友的身后,如果没有他的队友,那么他只能插入到队伍的最后.题目中包含以下操作: ...

  4. uva 540 - Team Queue(插队队列)

    首发:https://mp.csdn.net/mdeditor/80294426 例题5-6 团体队列(Team Queue,UVa540) 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队 ...

  5. UVA 540 Team Queue(模拟+队列)

    题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...

  6. UVa 10935 Throwing cards away I【队列】

    题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #inclu ...

  7. uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列

    题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...

  8. Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现

    今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...

  9. UVa 540 (团体队列) Team Queue

    题意: 每个人都属于一个团体,在排队的时候,如果他所在的团体有人在队伍中,则他会站到这个团体的最后.否则站到整个队伍的队尾. 输出每次出队的人的编号. 分析: 容易看出,长队中,在同一个团体的人是排在 ...

随机推荐

  1. C#使用基类的引用 and 虚方法和覆写方法

    结论:使用基类的引用,访问派生类对象时,得到的是基类的成员. 虚方法和覆写方法

  2. Jquery对象,DOM对象

    jquery对象就是通过Jquery包装Dom对象后产生的对象,Dom对象想要通过jquery进行操作,先转换为jquery对象: dom对象转化为jquery对象,使用$(dom对象): jquer ...

  3. access数据库多个left join示例

    代码: /// <summary> /// 分类检索 查询selectname /// </summary> public static DataTable GetSelect ...

  4. Winform开发框架之字典管理模块的更新,附上最新2013年全国最新县及县以上行政区划代码sql脚本

    在很多项目里面,字典管理是必备的项目模块,而这个又是比较通用的功能,因此可以单独做成一个通用字典管理,例如这个模块,可以通过集成的方式,使用在我的<Winform开发框架>.<WCF ...

  5. 四项技术 助你提高SQL Server的性能

    有时,为了让应用程序运行得更快,所做的全部工作就是在这里或那里做一些很小调整.但关键在于确定如何进行调整!迟早您会遇到这种情况:应用程序中的 SQL 查询不能按照您想要的方式进行响应.它要么不返回数据 ...

  6. ASP.NET MVC4 传递Model到View

    原文发表在:http://www.star110.com/Note/ReadArticle/60641215331146140043.html 开发环境:.NET MVC4 + EF6.0 模型: 1 ...

  7. 测试驱动开发(TDD)的思考

    极限编程 敏捷开发是一种思想,极限编程也是一种思想,它与敏捷开发某些目标是一致的.只是实现方式不同.测试驱动开发是极限编程的一部分. 1.极限编程这个思路的来源 Kent Beck先生最早在其极限编程 ...

  8. C# DevExpress 的gridControl或gridView数据导出失败解决方法

    来自:http://blog.csdn.net/lybwwp/article/details/8049464 谢谢 在使用DevExpress 的GridPanel控件的时候出现了一个莫名其妙的现象, ...

  9. mysql常见的运算符及使用

    mysql中有4类运算符,它们是: 算术运算符 比较运算符 逻辑运算符 位操作运算符 算术操作符 算术操作符是SQL中最基本的操作运算符,主要有一下几种运算符: +(加). -(减). *(乘). / ...

  10. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q70-Q72)

    Question 70You plan to create one provider Web Part and two consumer Web Parts.You need to ensure th ...