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

  1. 3
  2. 3 1 1 1
  3. 1 2
  4. 3 1 0 1
  5. 1 2
  6. 3 3 2 2
  7. 2 3
  8. 3 2
  9. 1 2

Sample Output

  1. 2
  2. 1
  3. 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代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #define MAXN 55
  4. using namespace std;
  5.  
  6. long long dp[MAXN][MAXN][MAXN];
  7.  
  8. int main()
  9. {
  10. int T,n,m,s,k,i,j,t,a[MAXN],b[MAXN];
  11. scanf("%d",&T);
  12. while(T--)
  13. {
  14. scanf("%d%d%d%d",&n,&m,&k,&s);
  15. for(i=;i<=m;i++)
  16. scanf("%d%d",a+i,b+i);
  17. memset(dp,,sizeof(dp));
  18. dp[][][s]=;
  19. for(i=;i<=m;i++)
  20. {
  21. dp[i][][s]=;
  22. for(j=;j<=i&&j<=k;j++)
  23. {
  24. dp[i][j][b[i]]=dp[i-][j-][a[i]];
  25. dp[i][j][a[i]]=dp[i-][j-][b[i]];
  26. for(t=;t<=n;t++)
  27. {
  28. dp[i][j][t]+=dp[i-][j][t];
  29. if(t!=a[i]&&t!=b[i])//最开始忘记考虑的一种情况
  30. dp[i][j][t]+=dp[i-][j-][t];
  31. }
  32. }
  33. }
  34. /*for(i=1;i<=m;i++,putchar('\n'))
  35. for(j=0;j<=k;j++,putchar('\n'))
  36. for(t=1;t<=n;t++)
  37. printf("%d ",dp[i][j][t]);
  38. printf("\n");*/
  39. for(s=,t=;t<=n;t++)
  40. if(dp[m][k][t]>dp[m][k][s])
  41. s=t;
  42. printf("%d\n",s);
  43. }
  44. return ;
  45. }

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. 【noiOJ】p8211 (PS:二分浮点数的精度问题)

    05:派 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 我的生日要到了!根据习俗,我需要将一些派分给大家.我有N个不同口味.不同大小的派.有F个朋友会来参加 ...

  2. 僵尸进程的产生和避免,如何kill杀掉linux系统中的僵尸defunct进程

    在 Unix系统管理中,当用ps命令观察进程的执行状态时,经常看到某些进程的状态栏为defunct,这就是所谓的"僵尸"进程."僵尸"进程是一个早已 死亡的进程 ...

  3. url 转码

    //URL解码 //-(NSString *)URLDecodedString:(NSString *)str //{ // NSString *decodedString=(__bridge_tra ...

  4. mysql 主从同步原理

    Replication 线程 Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql instance(我们 ...

  5. 单例 (JAVA)

    java中单例模式是一种常见的设计模式,以下是它的特点: 单例类只能有一个实例. 单例类必须自己创建自己的唯一实例. 单例类必须给所有其他对象提供这一实例 第一种(懒汉,线程不安全):  1 publ ...

  6. log4j2 配置文件

    首先pom文件如下 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  7. Linux_文件及文件夹[创建][复制][移动][删除][重命名]

    一.文件/文件夹创建 1.文件的创建 touch , vi/vim/nano , ... 语   法: touch [-acfm][-d <日期时间>][-r <参考文件或目 录&g ...

  8. Linux_文件查看

    文件查看 直接查看内容:cat , tac , nl 翻页查看:more , less 指定获取内容:head , tail 查看非纯文字文档:od 文件时间更新与新建:touch cat: 从首行开 ...

  9. zk 获取session,request,servletContext,response

    (参考:http://www.dotblogs.com.tw/rockywang/archive/2010/01/13/12995.aspx) HttpServletRequest request = ...

  10. Winform程序以Icon的形式显示在任务栏右下角

    Form最小化是指整个Form都缩小到任务栏上,但是是以Form的标题栏形式显示的, 若是想让Form以Icon的形式显示在任务栏右下角,则需要给Form添加一个NotifyIcon控件, 在使窗体最 ...