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 ...
随机推荐
- 朴素UNIX它-Linux CFS注视
该系列产品,被称为纯UNIX,但它也包含各种类别UNIX该系统的细节,自从完成我多年的学习笔记本系列文章,分析了各种UNIX,类UNIX思想和情感的实现. 这篇文章是比较短.只是分析Linux CFS ...
- Apache Curator获得真正的
Apache Curator获得真正的 Curator它是Netflix一家公司来源Zookeeper顾客,与Zookeeper相比于提供本地客户端,Curator的抽象层次更高,简化了Zookeep ...
- TaintDroid:智能手机监控实时隐私信息流跟踪系统(一)
1.1 摘要 现今,智能手机操作系统不能有效的提供给用户足够的控制权并且很清楚的了解到第三方的应用程序是如何使用其的隐私数据.我们使用了TaintDroid来阐明这个缺点,其是一个高效的,全系 ...
- go - 内置基础类型
Go 语言中包括以下内置基础类型: 布尔型:bool 整型:int int64 int32 int16 int8 uint8(byte) uint16 uint32 uint64 uint 浮点型:f ...
- 【从翻译mos文章】Weblogic AdminServer 启动fail,报错"unable to get file lock, will retry"
Weblogic AdminServer 启动fail,报错"unable to get file lock, will retry" 参考原始: Weblogic AdminSe ...
- git tag使用
#git tag command git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] ...
- 机械革命X5(MECHREVO MR-X5)开包检验
不废话.直接的问题,左右X5没有更具体的信息.为了通过有机会了解后续的选择,具体的数据被释放约: 首先看包装: 1.快递包裹,基于卖方这可以是不同的,包装各不相同 watermark/2/text/a ...
- HTML的标签使用
<p>段落标签</p>:段落标签 <hx>标题标签</hx>:标题标签,x代表1-6 <em>斜体</em>:显示的字体是斜的 ...
- 一个小的日常实践——高速Fibonacci数算法
上得厅堂.下得厨房.写得代码,翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:高速Fibonacci数算法 内容:先说说Fibonacci数列,它的定义是数列:f1,f2....fn有例如以下规律: ...
- POJ 1659 Frogs' Neighborhood(度序列组成)
意甲冠军 中国 依据Havel-Hakimi定理构图即可咯 先把顶点按度数从大到小排序 可图的话 度数大的顶点与它后面的度数个顶点相连肯定是满足的 出现了-1就说明不可图了 #include ...