您的位置:首页 > 其它

hdu 3076 ssworld VS DDD (概率与期望DP)

2017-03-13 18:44 381 查看

ssworld VS DDD

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2578    Accepted Submission(s): 509


[align=left]Problem Description[/align]
One day, sssworld and DDD play games together, but there are some special rules in this games.

They both have their own HP. Each round they dice respectively and get the points P1 and P2 (1 <= P1, P2 <= 6). Small number who, whose HP to reduce 1, the same points will remain unchanged. If one of them becomes 0 HP, he loses.

As a result of technical differences between the two, each person has different probability of throwing 1, 2, 3, 4, 5, 6. So we couldn’t predict who the final winner.

 

[align=left]Input[/align]
There are multiple test cases.

For each case, the first line are two integer HP1, HP2 (1 <= HP1, HP2 <= 2000), said the first player sssworld’s HP and the second player DDD’s HP.

The next two lines each have six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets point j. The input data ensures that the game always has an end.

 

[align=left]Output[/align]
One float with six digits after point, indicate the probability sssworld won the game.
 

[align=left]Sample Input[/align]

5 5
1.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 1.000
5 5
0.000 0.000 0.000 0.000 0.000 1.000
1.000 0.000 0.000 0.000 0.000 0.000

 

[align=left]Sample Output[/align]

0.000000
1.000000

 

[align=left]Source[/align]
2009 Multi-University Training Contest 17 - Host by NUDT

 

[align=left]Recommend[/align]
lcy   |   We have carefully selected several similar problems for you:  3069 3070 3071 3072 3073 
 

Statistic | Submit | Discuss
| Note

题解:概率与期望DP

f[i][j]表示第一个人的血量是i,第二个人的血量是j的概率。

f
[m]=1/(p+q) 其中p表示第一个人赢得概率,q表示第二个人赢得概率。

为啥初值不是1? 因为他可能很多次都是平局,一直再这个点上往复f
[m]=(1-p-q)*f
[m]

f[i][j]=(f[i+1][j]*q+f[i][j+1]*q)/(p+q)

在转移的时候需要注意,如果某个人的血量是0,那么他不会再更新别的状态。

那么最后的答案就是sigma f[i][0]

貌似读入的n,m是反着的。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 2003
using namespace std;
int n,m;
double a[7],b[7],f[3]
;
int main()
{
while (scanf("%d%d",&m,&n)!=EOF) {
for (int i=1;i<=6;i++) scanf("%lf",&a[i]);
for (int i=1;i<=6;i++) scanf("%lf",&b[i]);
double p=0,q=0;
for (int i=1;i<=6;i++)
for (int j=1;j<=6;j++) {
if (i==j) continue;
if (i>j) p+=a[i]*b[j];
else q+=a[i]*b[j];
}
if (p==0&&q==0) {
printf("%.6lf\n",0);
continue;
}
memset(f,0,sizeof(f));
f[n%2][m]=1/(p+q);
double ans=0;
for (int i=n;i>=0;i--) {
for (int j=m;j>=0;j--) {
if (i==n&&j==m) continue;
if (i==0||j==0) {
f[i%2][j]=(j?f[(i%2)^1][j]*q:0)+(i?f[i%2][j+1]*p:0);
continue;
}
f[i%2][j]=(f[(i%2)^1][j]*q+f[i%2][j+1]*p)/(p+q);
}
ans+=f[i%2][0];
}
printf("%.6lf\n",ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: