问题描述: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. Web 前端性能优化准则

    准则01:尽量减少http请求 “只有10%-20%的最终用户响应时间花在接收请求的HTML文档上,剩下的80%-90%时间花在HTML文档所引用的所有组件(图片,script,css,flash等等 ...

  2. 【Win10】【Win2D】实现控件阴影效果

    学过 WPF 的都知道,在 WPF 中,为控件添加一个阴影效果是相当容易的. <Border Width="100" Height="100" Backg ...

  3. 给文本框添加模糊搜索功能(“我记录”MVC框架下实现)

    步骤: 1.在文本框中输入内容时,触发keyup事件: 2.在keyup事件的处理方法中,通过Ajax调用控制器的方法: 3.在控制器方法中,搜索满足条件的数据,这里分页获取数据,且只取第一页的数据, ...

  4. C#中CookieContainer获取里面cookie值异常:InvokeMember("m_domainTable") FieldAccessException

    1.可能是主机提供商的 安全问题. Their hosts works in medium trustsecurity, and ASProxy needs a full trust security ...

  5. Mysql主从备份和SQL语句的备份

    MySQL服务器的主从配置,本来是一件很简单的事情,无奈不是从零开始,总是在别人已经安装好的mysql服务器之上 ,这就会牵扯到,mysql的版本,启动文件,等一些问题. http://www.cnb ...

  6. C#监控USB接口

    该C#代码实现监控USB接口是否有设备接入或拨出,包括多个U盘. using System; using System.IO; using System.Runtime.InteropServices ...

  7. SSM框架整合总结

    关于ssm整合的相关总结: 1.持久层--->mybatis:通过Spring 来管理持久层的 Mapper (相当于 dao 接口),来完成对数据库的操作. 首先我们回顾一下,在单独使用myb ...

  8. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了   ps -A | gr ...

  9. 各个平台的mysql重启命令

    linux平台及windows平台mysql重启方法 Linux下重启MySQL的正确方法: 1.通过rpm包安装的MySQL service mysqld restart 2.从源码包安装的MySQ ...

  10. PlayFramework 1 自定义标签 -- FastTags http://unmi.cc/category/javajee/playframework/

    最早是用 HTML 来自定义标签,现在觉得 HTML 写有关逻辑的代码就有点不伦不类了,HTML 里着重是显示代码.前有一篇  PlayFramework 1 模板应用 -- Java 对象扩展 学习 ...