HDU 3076 ssworld VS DDD (概率DP)

前端之家收集整理的这篇文章主要介绍了HDU 3076 ssworld VS DDD (概率DP)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

简单的概率DP。因为输入顺序反了,。错了N次。,,

代码如下:

#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL __int64
#define pi acos(-1.0)
const int mod=100000000;
const int INF=0x3f3f3f3f;
const double eqs=1e-8;
double dp[2001][2001];
int main()
{
        int hp1,hp2,i,j;
        double a[8],b[8],w1,w2,tmp,p;
        while(scanf("%d%d",&hp2,&hp1)!=EOF) {
                for(i=0; i<6; i++) {
                        scanf("%lf",&a[i]);
                }
                for(i=0; i<6; i++) {
                        scanf("%lf",&b[i]);
                }
                w1=w2=0;
                for(i=1; i<6; i++) {
                        for(j=0; j<i; j++) {
                                w1+=a[i]*b[j];
                                w2+=b[i]*a[j];
                        }
                }
                p=w1+w2;
                if(p) {
                        w1/=p;
                        w2/=p;
                }
                for(i=hp1; i>0; i--) {
                        for(j=hp2; j>=0; j--) {
                                if(i==hp1&&j==hp2) {
                                        dp[i][j]=1;
                                } else if(i==hp1) {
                                        dp[i][j]=dp[i][j+1]*w1;
                                } else if(j==hp2) {
                                        dp[i][j]=dp[i+1][j]*w2;
                                } else if(!j) {
                                        dp[i][j]=dp[i][j+1]*w1;
                                } else {
                                        dp[i][j]=dp[i+1][j]*w2+dp[i][j+1]*w1;
                                }
                        }
                }
                double ans=0;
                for(i=1; i<=hp1; i++) {
                        ans+=dp[i][0];
                }
                printf("%.6f\n",ans);
        }
        return 0;
}
原文链接:https://www.f2er.com/javaschema/285044.html

猜你在找的设计模式相关文章