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 ofm 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 integerN (N ≈ 100), then
N cases follow.

The first line of each test case contains 4 integers n, m,
k
and s(0 < sn ≤ 50, 0 ≤ km ≤ 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 integersai and
bi (1 ≤ ai, bi
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
  1.  
  1. 题目大意:N个容器,M次两两交换。当中K次是能够知道的,一開始珠子放在当中一个容器里。问你交换完以后,珠子在哪个容器的概率最大
  1.  
  1. 思路:用DP[m][k][n] 表示 m次交换,知道了当中的k次,结尾为n的方案数
  1.  
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. using  namespace std;
  6. typedef long long ll;
  7. const  int maxn = 60;
  8. int n,m,k,s;
  9. int A[maxn],B[maxn];
  10. ll dp[maxn][maxn][maxn];
  11. int main(){
  12.     int ncase;
  13.     cin >> ncase;
  14.     while(ncase--){
  15.         scanf("%d%d%d%d",&n,&m,&k,&s);
  16.         for(int i = 1; i <= m; i++){
  17.             scanf("%d%d",&A[i],&B[i]);
  18.         }
  19.         memset(dp,0,sizeof dp);
  20.         dp[0][0][s] = 1;
  21.         for(int i = 1; i <= m; i++){
  22.             dp[i][0][s] = 1;
  23.             for(int j = 1; j <= i&&j <= k; j++){
  24.                 dp[i][j][A[i]] = dp[i-1][j-1][B[i]];
  25.                 dp[i][j][B[i]] = dp[i-1][j-1][A[i]];
  26.                 for(int d = 1; d <= n; d++){
  27.                     dp[i][j][d] += dp[i-1][j][d];
  28.                     if(d!=A[i]&&d!=B[i]){
  29.                         dp[i][j][d] += dp[i-1][j-1][d];
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.         int idx = 1;
  35.         for(int i = 2; i <= n; i++){
  36.             if(dp[m][k][i] > dp[m][k][idx]){
  37.                 idx = i;
  38.             }
  39.         }
  40.         cout<<idx<<endl;
  41.     }
  42.     return 0;
  43. }
  44.  
  1.  

版权声明:本文博客原创文章,博客,未经同意,不得转载。

ZOJ3605-Find the Marble(可能性DP)的更多相关文章

  1. zoj3605 Find the Marble --- 概率dp

    n个杯子.球最開始在s位置.有m次换球操作,看到了k次,看的人依据自己看到的k次猜球终于在哪个位置,输出可能性最大的位置. dp[m][k][s]表示前m次操作中看到了k次球终于在s的频率. #inc ...

  2. [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem

    意甲冠军: 给n快报,和m频率. 然后进入n字母出现的概率 然后给目标字符串str 然后问m概率倍的目标字符串是敲数量. 思维: AC自己主动机+可能性dp简单的问题. 首先建立trie图,然后就是状 ...

  3. ZOJ 3605 Find the Marble(dp)

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

  4. 可能性dp+减少国家HDU4336

    Card Collector Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Subm ...

  5. zoj 3822 Domination (可能性DP)

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  6. CF 148D. Bag of mice (可能性DP)

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. poj2096--Collecting Bugs(可能性dp第二弹,需求预期)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 2678   Accepted: 1302 ...

  8. UVA 10529 Dumb Bones 可能性dp 需求预期

    主题链接:点击打开链接 题意: 要在一条直线上摆多米诺骨牌. 输入n, l, r 要摆n张排,每次摆下去向左倒的概率是l, 向右倒的概率是r 能够採取最优策略.即能够中间放一段.然后左右两边放一段等, ...

  9. hdu 4870 Rating(可能性DP&amp;高数消除)

    Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

随机推荐

  1. dbus 和 policykit 实例篇(python) ()转

    使用policykit 的程序一般都有一个dbus daemon程序来完成相关操作,这个dbus daemon 会在系统注册一个system bus 服务名,用于响应要求root privileged ...

  2. spring来源理解-BeanFactory子类XmlBeanFactory创建过程

    BeanFactory 1:BeanFactory什么: 官方解释The root interface for accessing a Spring bean container,翻译成中文sprin ...

  3. zoj3829 Known Notation --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    根据规则,可以发现,一*之前必须有至少2数字.一(11*)这反过来可以被视为一数字. 因此,总位数必须大于*号码,或者你会加入数字. 添加数字后,,为了确保该解决方案将能够获得通过交流.那么肯定是*放 ...

  4. NGUI简单背包系统的实现

    一.利用txt文件存储游戏物品信息 首先在asset下创建一个txt文件,这里我们命名为objectsInfoList.txt,并将其拖放到unity Project视图中. 其中txt中我们先存放一 ...

  5. CacheManager

    .Net缓存管理框架CacheManager Cache缓存在计算机领域是一个被普遍使用的概念.硬件中CPU有一级缓存,二级缓存, 浏览器中有缓存,软件开发中也有分布式缓存memcache, redi ...

  6. 不一样的味道--Html和Xml解析、格式、遍历

    很多其它内容查看官网:http://www.tinygroup.org TinyXmlParser一切以简单.有用.高速为主. 演示样例1:Xml字符串解析 比方,我们要解析一段Xml字符串,简单例如 ...

  7. Web APi之认证

    Web APi之认证(Authentication)两种实现方式后续[三](十五)   前言 之前一直在找工作中,过程也是令人着实的心塞,最后还是稳定了下来,博客也停止更新快一个月了,学如逆水行舟,不 ...

  8. [原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇)

    原文:[原创].NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇) .NET 业务框架开发实战之十 第一阶段总结,深入浅出,水到渠成(后篇) 前言:接着上篇来. 系列文章链接: [ ...

  9. ftk学习记录(多形式的文章)

    [声明:版权全部.欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 在上周末的博客中,我们谈到了list view,今天能够看看效果图怎样. 假设大家细心一点,能够 ...

  10. 50一个Android开发技巧(01 利用好layout_weight属性)

    问题:如何将一个Button放置在布局的中间,并设置其宽度parent的50%? 分析:问题想要达到的效果应该是这样: (原文地址:http://blog.csdn.net/vector_yi/art ...