http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3605

Find the Marble


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Alice and Bob are playing a game. This game is played with several identical pots and one marble. When the game starts, Alice puts the pots in one line and puts the marble in one of the pots. After that, Bob cannot see the inside of the pots. Then Alice makes a sequence of swappings and Bob guesses which pot the marble is in. In each of the swapping, Alice chooses two different pots and swaps their positions.

Unfortunately, Alice's actions are very fast, so Bob can only catch k of m swappings and regard these k swappings as all actions Alice has performed. Now given the initial pot the marble is in, and the sequence of swappings, you are asked to calculate which pot Bob most possibly guesses. You can assume that Bob missed any of the swappings with equal possibility.

Input

There are several test cases in the input file. The first line of the input file contains an integer N (N ≈ 100), then N cases follow.

The first line of each test case contains 4 integers nmk and s(0 < s ≤ n ≤ 50, 0 ≤ k ≤ m ≤ 50), which are the number of pots, the number of swappings Alice makes, the number of swappings Bob catches and index of the initial pot the marble is in. Pots are indexed from 1 to n. Then m lines follow, each of which contains two integers ai and bi (1 ≤ aibi ≤ n), telling the two pots Alice swaps in the i-th swapping.

Outout

For each test case, output the pot that Bob most possibly guesses. If there is a tie, output the smallest one.

Sample Input

3
3 1 1 1
1 2
3 1 0 1
1 2
3 3 2 2
2 3
3 2
1 2

Sample Output

2
1
3

Author: GUAN, Yao
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest

分析;

Alice和Bob在玩一个游戏,该游戏需要n个杯子和一个石头,开始时石头被罩在在某个杯子里,Alice可交换任意两个杯子,经过一系列的交换,由Bob猜石头在哪个杯子里,交换总共m步,但Bob只看到了其中的k步,问Bob猜哪个杯子的可能性最大。

第一感觉就是和组合(在n个数里取m个有多少种)很相似,再看题目因为顺序是一定的,即选了k步之后,顺序只有一种。

c[n][m]=c[n-1][m-1]+c[n-1][m];

具体编码的时候只考虑到交换的两个杯子而忘记其他杯子在选择时的值也要加上c[n-1][m-1];

 

AC代码:

 #include<cstdio>
#include<cstring>
#define MAXN 55
using namespace std; long long dp[MAXN][MAXN][MAXN]; int main()
{
int T,n,m,s,k,i,j,t,a[MAXN],b[MAXN];
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&m,&k,&s);
for(i=;i<=m;i++)
scanf("%d%d",a+i,b+i);
memset(dp,,sizeof(dp));
dp[][][s]=;
for(i=;i<=m;i++)
{
dp[i][][s]=;
for(j=;j<=i&&j<=k;j++)
{
dp[i][j][b[i]]=dp[i-][j-][a[i]];
dp[i][j][a[i]]=dp[i-][j-][b[i]];
for(t=;t<=n;t++)
{
dp[i][j][t]+=dp[i-][j][t];
if(t!=a[i]&&t!=b[i])//最开始忘记考虑的一种情况
dp[i][j][t]+=dp[i-][j-][t];
}
}
}
/*for(i=1;i<=m;i++,putchar('\n'))
for(j=0;j<=k;j++,putchar('\n'))
for(t=1;t<=n;t++)
printf("%d ",dp[i][j][t]);
printf("\n");*/
for(s=,t=;t<=n;t++)
if(dp[m][k][t]>dp[m][k][s])
s=t;
printf("%d\n",s);
}
return ;
}

zjuoj 3605 Find the Marble的更多相关文章

  1. ZOJ 3605 Find the Marble(dp)

    Find the Marble Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice and Bob are playing a game. ...

  2. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  3. HDU 3605:Escape(最大流+状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...

  4. HDU(3605),二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  5. HDU 3605

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 用最大流做的,G++超时,C++可以过,看别人写的叫二分图多重匹配,还不会这玩意一会学学 显然的最大流模型 ...

  6. [RxJS] Introduction to RxJS Marble Testing

    Marble testing is an expressive way to test observables by utilizing marble diagrams. This lesson wi ...

  7. [RxJS] Marble diagrams in ASCII form

    There are many operators available, and in order to understand them we need to have a simple way of ...

  8. Merkaartor,Marble,QGIS等等

    Merkaartor介绍 Merkaartor是Qt开发开源的OpenStreetMap(下简称osm)数据的编辑器,这里简单列出相关资源.方面基于osm数据的开发. Merkaartor支持osm地 ...

  9. ZOJ3605-Find the Marble(可能性DP)

    Find the Marble Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice and Bob are playing a game. ...

随机推荐

  1. iOS9 tableVIewCell的分割线不显示,只有在滑动的时候才显示?

    1.如果用6plus模拟器的话,电脑分辨率达不到那么高,因此就看不到分割线. 2.把模拟器换成6s 或 5s,就没问题了.

  2. 《自制编程语言》笔记:使用yacc与lex制作简单计算器

    1.代码 1.1)test.l 1.2)test.y 1.3)Makefile (因为是在linux环境下,所以使用了Makefile) 2.编译与运行 2.1)编译 2.2)运行 1.代码(也可以在 ...

  3. 在DataGridView控件中加入ComboBox下拉列表框的实现

    在DataGridView控件中加入ComboBox下拉列表框的实现 转自:http://www.cnblogs.com/luqingfei/archive/2007/03/28/691372.htm ...

  4. Redis在windows下的安装使用

    下载的windows版本是redis-2.0.2,解压到D盘下: D:\redis-2.0.2 启动Redis服务(conf文件指定配置文件,若不指定则默认): D:\redis-2.0.2>r ...

  5. Radar Installation

    Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...

  6. 给ListView视图添加行号

    最后的效果如下: 更新,集成一个独立的模块而不改变源文件的方式更为稳妥. 购买地址:https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-26531 ...

  7. 第一个django

    4.创建第一个Django工程 Django环境算是配置完成了,你可以到命令提示符下创建第一个Django应用,进入某个目录,执行django-admin.py startproject myproj ...

  8. 2016HUAS暑假集训训练2 A - Is It A Tree?

    Description A tree is a well-known data structure that is either empty (null, void, nothing) or is a ...

  9. zju(11)在IAR中移植ucos到msp430

    准备材料 1.在TI官网上下载430的固件库,我用的是msp430f5528的板子,下载的是F5xx_F6xx_Core_Lib 地址http://www.ti.com/tool/msp-exp430 ...

  10. js 所有事件列表

    javascript事件列表解说 事件 浏览器支持 解说 一般事件 onclick IE3.N2 鼠标点击时触发此事件 ondblclick IE4.N4 鼠标双击时触发此事件 onmousedown ...