ZOJ 3605 Find the Marble(三维dp)
来源:互联网 发布:c语言九九乘法表 编辑:程序博客网 时间:2024/09/21 09:02
n个杯子,有一个石头放在第s号杯子里,然后交换这些杯子m次,只能记住k次,每次交换被忘掉的概率相同,那个猜的人最可能猜哪号杯里有石头。
dp[i][j][t] 代表从第i个交换中有j次没看到。然后这是第t个情况为dp[i][j][t]。选择一个最大的dp[m][m-k][ti]输出ti。状态转移: if(能看见) if(t==x) dp[i][j][t] += dp[i-1][j][y] else if(t == y) dp[i][j][t] += dp[i-1][j][x] else dp[i][j][t] += dp[i-1][j][t]。
if(看不见) dp[i][j][t] += dp[i-1][j-1][t]。
注意这里是枚举所有的可能所以最终的dp表示由看的见和看不见的和加起来。
初始化的时候要把dp[0][0][s] = 1。因为一个都不看的时候只在s上。
最后遍历输出最大可能性的结果。
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 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 integers ai 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
33 1 1 11 23 1 0 11 23 3 2 22 33 21 2
Sample Output
213
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-7#define M 1000100//#define LL __int64#define LL long long#define INF 0x3f3f3f3f#define PI 3.1415926535898const int maxn = 110;using namespace std;LL dp[maxn][maxn][maxn];struct node{ int x, y;} f[maxn];int main(){ int T; cin >>T; while(T--) { int n, m, k, s; cin >>n>>m>>k>>s; memset(dp, 0 , sizeof(dp)); for(int i = 1; i <= m; i++) cin >>f[i].x>>f[i].y; dp[0][0][s] = 1; for(int i=1; i<=m; i++) { for(int j=0; j<=i; j++)//从0开始; { for(int t=1; t<=n; t++) { if(j<i) { if(t == f[i].x) dp[i][j][t] += dp[i-1][j][f[i].y]; else if(t == f[i].y) dp[i][j][t] += dp[i-1][j][f[i].x]; else dp[i][j][t] += dp[i-1][j][t]; } if(j>0) dp[i][j][t]+=dp[i-1][j-1][t]; } } } s=1; for(int t=2; t<=n; t++) if(dp[m][m-k][t]>dp[m][m-k][s]) s=t; cout<<s<<endl; } return 0;}
- ZOJ 3605 Find the Marble(三维dp)
- ZOJ 3605 Find the Marble(dp啊 三维)
- ZOJ 3605 Find the Marble(DP)
- zoj 3605 Find the Marble 计数dp
- zoj 3605 Find the Marble (概率dp)
- 【DP】ZOJ 3605 Find the Marble
- ZOJ 3605 Find the Marble(dp)
- ZOJ 3605-F - Find the Marble-DP
- zoj 3605 Find the Marble (dp)
- zoj3605 Find the Marble(三维dp)
- ZOJ 3605Find the Marble
- ZOJ 3605 Find the Marble
- ZOJ 3605Find the Marble
- ZOJ 3605 Find the Marble
- Find the Marble ZOJ
- ZOJ3605-Find the Marble(概率DP)
- zoj3605 Find the Marble --- 概率dp
- ZOj3605--- Find the Marble(概率dp)
- 交通灯管理系统 设计
- Cocos2d-x简单的Log类封装
- jquery获取父级元素、子级元素、兄弟元素的方法
- 2014.02
- 18岁生日
- ZOJ 3605 Find the Marble(三维dp)
- 学习 Linux,101: 管理文件权限和所有权
- 字符串的所有组合问题,输入三个字符a,b,c,则它们的组合有a,b,c,ab,ac,bc,abc
- lol 发新帖
- poi导出为excel文件
- usaco 月赛 2003 Fall Popular Cows 受欢迎的奶牛 题解
- Maximum Subarray
- 非归档模式下,redo丢失案例
- 这些年我读过的技术经典图书(附电子版下载地址)