08_Queue(队列UVa 10128)
问题描述: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)的更多相关文章
- 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表示此时排第 ...
- UVa 12100打印队列(队列)
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA.540 Team Queue (队列)
UVA.540 Team Queue (队列) 题意分析 有t个团队正在排队,每次来一个新人的时候,他可以插入到他最后一个队友的身后,如果没有他的队友,那么他只能插入到队伍的最后.题目中包含以下操作: ...
- uva 540 - Team Queue(插队队列)
首发:https://mp.csdn.net/mdeditor/80294426 例题5-6 团体队列(Team Queue,UVa540) 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队 ...
- UVA 540 Team Queue(模拟+队列)
题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...
- UVa 10935 Throwing cards away I【队列】
题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #inclu ...
- uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列
题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...
- Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现
今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...
- UVa 540 (团体队列) Team Queue
题意: 每个人都属于一个团体,在排队的时候,如果他所在的团体有人在队伍中,则他会站到这个团体的最后.否则站到整个队伍的队尾. 输出每次出队的人的编号. 分析: 容易看出,长队中,在同一个团体的人是排在 ...
随机推荐
- 2015 Multi-University Training Contest 1 - 1002 Assignment
Assignment Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Mean: 给你一个数列和一个k,求连续区间的极值之 ...
- istView的项移除
如标题所言,是做删除ListView绑定项的功能的:鉴于这个功能当时确实花费了很多时间,并且网上也找不到删除所需的案例,所以,我就做了一份案例,仅供各位前辈和同行进行参考,如有不当之处,还望指点,我将 ...
- jquery 字符串转dom对象及对该对象使用选择器查询
<script> $(document).ready(function () { var htmlStr = '<div id="outerDiv">< ...
- Winform中的窗体一些常用属性
Winform窗体的常用窗体属性 1)窗体全屏显示 this.DesktopBounds = Screen.GetWorkingArea(this); //全屏显示桌面 注:可以放在初始化方法中,也 ...
- 将表数据生成Insert脚本
set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo-- =============================================-- Author ...
- YEdit
YEdit YEdit is a YAML editor for Eclipse. See the wiki for more details Installation Use the Eclipse ...
- u-boot移植总结(一)start.S分析
本次移植u-boot-2010.09是基于S3C2440的FL440板子,板子自带NANDFLASH而没有NORFLASH,所以在U-BOOT启动的过程中必须实现从NANDFLASH到SDRAM的重定 ...
- DoTween小结
using UnityEngine; using System.Collections; using DG.Tweening; public class GetStart : MonoBehaviou ...
- Yii路径总结
如果是 // 就会默认去调 protected/views/layouts //代表 绝对路径 其实 就是 绝对和相对的关系 /代表相对路径,如module/user下的layout 用单斜杠的话默认 ...
- 非线性数据拟合-nls
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...