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 ...
随机推荐
- [ACM] POJ 3687 Labeling Balls (拓扑排序,反向生成端)
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10161 Accepted: 2810 D ...
- hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)
Walk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- Routeros 计划任务连线/断线ADSL
老板吩咐,要求晚上11点前断网,目的是让大家伙早睡早起. 不想使用Panabit来做策略,阿童木的D2500C还是性能不足,就用ROS的计划任务. 第1步 校时 时间要准,要不控制个乱七八糟. 操作路 ...
- bat脚本命令
注:本文转载地址 http://www.cnblogs.com/yefengmeander/archive/2011/12/01/2887978.html 1.Echo 命令 打开回显或关闭请求回显 ...
- 在VC/MFC中嵌入Google地图——图文并茂
近期须要实验室须要将在无人机地面站中嵌入地图,在网上找了非常多资料,最终有些眉目了, 首先.做这个须要用到的知识有.MFC控件.MFC类库.JavaScript脚本语言.Google API.Goog ...
- nyoj 47 江 河问题 【贪婪】
经典的贪婪. 两种方案:一个:让我们来最快,第二快,在过去的第一,最快的回.然后最慢,最慢第二,在过去.次最快的回来a[0]+a[1]+a[1]+a[n-1] 二:最快的和最慢的过去,最快的回来,最快 ...
- redirect的错误用法asp.net怎么使用自定义错误
工作了几年,写过程序也运营过网站,自定义错误也很熟悉了,最近再做项目发现有同事写了这样的代码 if (action != null) { id = Request.QueryString[" ...
- SNMP WINDOWS系统的命令行工具下载
SNMP windows系统的命令行工具snmputil.exe下载链接:请点击
- Extjs Web Desktop申请书
今天我Web Desktop应用基本完成.多语言支持.现有asp,php,jsp版本号. 废话拍了几张照片让大家有一个直观的了解: watermark/2/text/aHR0cDovL2Jsb2cuY ...
- ISAPI_Rewrite不起作用的N种原因
现在经常用到ISAPI_Rewrite,遇到的问题就是在本地测试的时候,一切没有问题,到服务器上,竟然不起作用.郁闷~经过我的一些探索,发现了比起作用的原因如下:1.IIS_WPG对ISAPI_Rew ...