zjuoj 3605 Find the Marble
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3605
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 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
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
Author: GUAN, Yao
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest
分析;
Alice和Bob在玩一个游戏,该游戏需要n个杯子和一个石头,开始时石头被罩在在某个杯子里,Alice可交换任意两个杯子,经过一系列的交换,由Bob猜石头在哪个杯子里,交换总共m步,但Bob只看到了其中的k步,问Bob猜哪个杯子的可能性最大。
第一感觉就是和组合(在n个数里取m个有多少种)很相似,再看题目因为顺序是一定的,即选了k步之后,顺序只有一种。
c[n][m]=c[n-1][m-1]+c[n-1][m];
具体编码的时候只考虑到交换的两个杯子而忘记其他杯子在选择时的值也要加上c[n-1][m-1];
AC代码:
#include<cstdio>
#include<cstring>
#define MAXN 55
using namespace std; long long dp[MAXN][MAXN][MAXN]; int main()
{
int T,n,m,s,k,i,j,t,a[MAXN],b[MAXN];
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&m,&k,&s);
for(i=;i<=m;i++)
scanf("%d%d",a+i,b+i);
memset(dp,,sizeof(dp));
dp[][][s]=;
for(i=;i<=m;i++)
{
dp[i][][s]=;
for(j=;j<=i&&j<=k;j++)
{
dp[i][j][b[i]]=dp[i-][j-][a[i]];
dp[i][j][a[i]]=dp[i-][j-][b[i]];
for(t=;t<=n;t++)
{
dp[i][j][t]+=dp[i-][j][t];
if(t!=a[i]&&t!=b[i])//最开始忘记考虑的一种情况
dp[i][j][t]+=dp[i-][j-][t];
}
}
}
/*for(i=1;i<=m;i++,putchar('\n'))
for(j=0;j<=k;j++,putchar('\n'))
for(t=1;t<=n;t++)
printf("%d ",dp[i][j][t]);
printf("\n");*/
for(s=,t=;t<=n;t++)
if(dp[m][k][t]>dp[m][k][s])
s=t;
printf("%d\n",s);
}
return ;
}
zjuoj 3605 Find the Marble的更多相关文章
- ZOJ 3605 Find the Marble(dp)
Find the Marble Time Limit: 2 Seconds Memory Limit: 65536 KB Alice and Bob are playing a game. ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- HDU(3605),二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 3605
http://acm.hdu.edu.cn/showproblem.php?pid=3605 用最大流做的,G++超时,C++可以过,看别人写的叫二分图多重匹配,还不会这玩意一会学学 显然的最大流模型 ...
- [RxJS] Introduction to RxJS Marble Testing
Marble testing is an expressive way to test observables by utilizing marble diagrams. This lesson wi ...
- [RxJS] Marble diagrams in ASCII form
There are many operators available, and in order to understand them we need to have a simple way of ...
- Merkaartor,Marble,QGIS等等
Merkaartor介绍 Merkaartor是Qt开发开源的OpenStreetMap(下简称osm)数据的编辑器,这里简单列出相关资源.方面基于osm数据的开发. Merkaartor支持osm地 ...
- ZOJ3605-Find the Marble(可能性DP)
Find the Marble Time Limit: 2 Seconds Memory Limit: 65536 KB Alice and Bob are playing a game. ...
随机推荐
- Invalid escape sequence(valid ones are \b \t \n \f \r \" \' \\)
Invalid escape sequence(valid ones are \b \t \n \f \r \" \' \\) 在运行eclipse的相关程序代码时遇到了报错信息,查看控制台 ...
- POI-HSSF and POI-XSSF - Java API To Access Microsoft Excel Format Files
一.概述 HSSF和XSSF是apache开源项目POI中实现java面向Excel的两个接口.两者的区别在于,HSSF适用于Excel '97(-2007)文档,而XSSF适用于Excel 2007 ...
- 类库,委托,is和as运算符,泛型集合
类库:其实就是一堆类文件,只不过用户看不到这些类的源代码,保密性好. 优点:保密性好缺点:如果这个方法不好用,使用者无法自己去更改它. 类文件是.cs 类库是.dll 新建项目为类库,在debu ...
- 修改apache的默认访问目录
在我们新安装好apache后,我们如果输入我们的ip地址,我们访问到的是apache中的www文件夹. 这个www文件夹就是我们的默认目录,而这个目录是可以修改的: 打开conf文件夹里的httpd. ...
- php循环删除文件目录及文件
删除文件及目录: //循环删除目录和文件函数 function delDirAndFile( $dirName ) { if ( $handle = opendir( "$dirName&q ...
- jq实现点击表格无刷新修改数据,优化版
<!-------------------修改密码-------------------------- > $("#pwd").live("click&quo ...
- Oracle加密表空间进行数据加密的示例
接上篇:http://www.cnblogs.com/myrunning/p/4292049.html 1查看数据库版本 2查看当前数据库表空间 从这里看到我们此时数据库里没有加密表空间. 3创建加密 ...
- 关于WebDAV带来的网站潜在安全问题的疑问
WebDAV:分布式创作和版本控制协议 (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1协议的通信协议.它扩展了HTTP 1 ...
- 关于export 和 require(import)的一些技巧和常用方法
多重export 这样做的好处是可以在引入页面按需加载,也非常的清晰加载了哪一些东西 //exportexport const setError = ({dispatch}, error) => ...
- BizTalk动手实验(四)Schema开发测试
1 课程简介 通过本课程熟悉Schema的相关开发技术 2 准备工作 1. 熟悉XML.XML Schema.XSLT等相关XML开发技术 2. 新建BizTalk空项目 3 演示 3.1 格式化XM ...