ZOJ3605-Find the Marble(可能性DP)
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 < 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 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
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
题目大意:N个容器,M次两两交换。当中K次是能够知道的,一開始珠子放在当中一个容器里。问你交换完以后,珠子在哪个容器的概率最大
思路:用DP[m][k][n] 表示 m次交换,知道了当中的k次,结尾为n的方案数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector> using namespace std;
typedef long long ll;
const int maxn = 60;
int n,m,k,s;
int A[maxn],B[maxn];
ll dp[maxn][maxn][maxn];
int main(){ int ncase;
cin >> ncase;
while(ncase--){
scanf("%d%d%d%d",&n,&m,&k,&s);
for(int i = 1; i <= m; i++){
scanf("%d%d",&A[i],&B[i]);
}
memset(dp,0,sizeof dp);
dp[0][0][s] = 1;
for(int i = 1; i <= m; i++){
dp[i][0][s] = 1;
for(int j = 1; j <= i&&j <= k; j++){
dp[i][j][A[i]] = dp[i-1][j-1][B[i]];
dp[i][j][B[i]] = dp[i-1][j-1][A[i]];
for(int d = 1; d <= n; d++){
dp[i][j][d] += dp[i-1][j][d];
if(d!=A[i]&&d!=B[i]){
dp[i][j][d] += dp[i-1][j-1][d];
}
}
}
}
int idx = 1;
for(int i = 2; i <= n; i++){
if(dp[m][k][i] > dp[m][k][idx]){
idx = i;
}
}
cout<<idx<<endl;
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
ZOJ3605-Find the Marble(可能性DP)的更多相关文章
- zoj3605 Find the Marble --- 概率dp
n个杯子.球最開始在s位置.有m次换球操作,看到了k次,看的人依据自己看到的k次猜球终于在哪个位置,输出可能性最大的位置. dp[m][k][s]表示前m次操作中看到了k次球终于在s的频率. #inc ...
- [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem
意甲冠军: 给n快报,和m频率. 然后进入n字母出现的概率 然后给目标字符串str 然后问m概率倍的目标字符串是敲数量. 思维: AC自己主动机+可能性dp简单的问题. 首先建立trie图,然后就是状 ...
- ZOJ 3605 Find the Marble(dp)
Find the Marble Time Limit: 2 Seconds Memory Limit: 65536 KB Alice and Bob are playing a game. ...
- 可能性dp+减少国家HDU4336
Card Collector Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- zoj 3822 Domination (可能性DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- 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 ...
- poj2096--Collecting Bugs(可能性dp第二弹,需求预期)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2678 Accepted: 1302 ...
- UVA 10529 Dumb Bones 可能性dp 需求预期
主题链接:点击打开链接 题意: 要在一条直线上摆多米诺骨牌. 输入n, l, r 要摆n张排,每次摆下去向左倒的概率是l, 向右倒的概率是r 能够採取最优策略.即能够中间放一段.然后左右两边放一段等, ...
- hdu 4870 Rating(可能性DP&高数消除)
Rating Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
随机推荐
- Nagios监控生产环境redis群集服务战
前言: 曾经做了cacti上展示redis性能报表图.能够看到redis的性能变化趋势图,可是还缺了实时报警通知的功能,如今补上这一环节. 在redis服务瓶颈或者异常时候即使报警通知,方便d ...
- TCP/IP详细说明--滑模、拥塞窗口、慢启动、Negle算法
TCP的数据流大致能够分为两类,交互数据流与成块的数据流. 交互数据流就是发送控制命令的数据流.比方relogin,telnet.ftp命令等等.成块数据流是用来发送数据的包,网络上大部分的TCP包都 ...
- .net SMTP发送Email 更新(可带附件)
public static void sendEmail(string toAddress, string emailbody) { var fromAddre ...
- vc++笔记十一
一.LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 连接器LNK是通过调用cvtres.exe完毕文件向coff格式的转换的,所以出现这样的错误的原因就是cvtres.exe出现了问题 ...
- Java引用类型变量
Java引用类型变量 1.编译时类型:由声明该变量时使用的类型决定 2.执行时类型:由实际赋给该变量的对象决定 类型不一致的假设编译时类型和执行,可能会出现多态性 版权声明:本文博主原创文章.博 ...
- ueditor问题解决
ueditor图片无法上传? 解决: imageUp.ashx 去掉这一行 <%@ Assembly Src="Uploader.cs" %> 参考: http://w ...
- 自动同步Android源代码的脚本(repo sync)
#!/bin/bash echo "================start repo sync====================" repo sync -j5 ]; do ...
- Lua 服务器与客户端实例(转)
=============================================================== 服务器,main.lua ======================= ...
- or1200中IMMU分析(续)
下面内容摘自<步步惊芯--软核处理器内部设计分析>一书 2 IMMU中的特殊寄存器 OR1200处理器中的IMMU包括第2组特殊寄存器,如表10.1所看到的. ITLBW0MRx是指令TL ...
- C#中禁止程序多开
原文:C#中禁止程序多开 方法一.使用Mutex bool createdNew; //返回是否赋予了使用线程的互斥体初始所属权 System.Threading.Mutex i ...