Another Sith Tournament
来源:互联网 发布:淘宝网户外服装男 编辑:程序博客网 时间:2024/05/30 05:41
题目:
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive.
Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.
题意:有这么几个人打拳击比赛,规则是按顺序出场,胜者留下,最后留下的为冠军,某个人可以控制出场顺序,知道所有人面对所有人的胜率,问他的最大胜率是多少。
分析:只是一道状态压缩的概率dp,首先不超过18个人,那么可以用18位来枚举出所有已经上场的人的状况,那么dp[1<<20][20]第一维代表上场过的人,第二维表示某个人是目前胜利者的概率,之后某个人的在某些人当中胜出的最大概率就是:他最后上场,与之前的胜者较量胜利的概率,以及他先上场,胜利到最后,在与当中缺失那位战斗胜利的概率的最大值。这样状态转移公式就有了。问题得以解决。
题解:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <map>#include <string>#include <cstring>#include <functional>#include <cmath>#include <cctype>#include <cfloat>#include <climits>#include <complex>#include <deque>#include <list>#include <set>#include <utility>using namespace std;int n;double s[20][20];double dp[1<<20][20];int main(){//freopen("in.txt","r",stdin);while(~scanf("%d",&n)){memset(dp,0.0,sizeof(dp));for(int p=1;p<=n;p++)for(int q=1;q<=n;q++)cin>>s[p][q];dp[1][1]=1;for(int i=1;i<(1<<n);i++)for(int j=1;j<=n;j++)if((1<<(j-1)|i)==i)for(int k=1;k<=n;k++)//if(j!=k&&(1<<(k-1)|i)==i)//dp[i][j]=(dp[i][j]>dp[i-(1<<(j-1))][k]*s[k][j]+dp[i-(1<<(k-1))][j]*s[j][k])?(dp[i][j]):(dp[i-(1<<(j-1))][k]*s[k][j]+dp[i-(1<<(k-1))][j]*s[j][k]);double ans=0;for(int t=0;t<=n;t++)ans=(ans>dp[(1<<n)-1][t])?ans:dp[(1<<n)-1][t];printf("%.15lf\n",ans);}return 0;}
- cf678E. Another Sith Tournament
- Another Sith Tournament
- [CF678E] Another Sith Tournament([JZOJ4648] 锦标赛)
- Codeforces 678E(Another Sith Tournament)
- cf 678E Another Sith Tournament
- Educational Codeforces Round 13 E. Another Sith Tournament
- 【Codeforces 696B】Another Sith Tournament &【JZOJ 4647】寻找
- 【Codeforces 678E】Another Sith Tournament &【JZOJ 4648】锦标赛
- Codeforces 678E Another Sith Tournament(状压dp)
- Codeforces 678E Another Sith Tournament(状压dp,概率dp)
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
- CF678E Another Sith Tournament(概率dp+状压dp)
- Educational Codeforces Round 13 E. Another Sith Tournament 状态压缩dp
- Knight Tournament
- Knight Tournament
- Knockout Tournament
- [agc009b]Tournament
- Archery Tournament
- 经常被问到的java面试题
- 隐式Intent启动Activity,action不能使用@string配置
- LeetCode: Two Sum
- Java类加载器总结
- POJ3944 Spherical Mirrors
- Another Sith Tournament
- POJ 3213 矩阵乘法(优化)
- 跑马灯
- mock和fake的区别
- 53. Maximum Subarray-动态规划/分治
- 编译google Zxing,实现安卓一、二维码的扫描与生成
- 一个简单的linked list问题
- Java深度历险(二)——Java类的加载、链接和初始化
- 最多约数问题。正整数 x 的约数是能整除x的正整数,其约数的个数记为div(x),例如div(10)=4。设 a 和 b 是两个正整数,找出 a 和 b 之间约数个数最多的数 x 的约数个数。 样例