加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

HDU 3076 ssworld VS DDD (概率DP)

发布时间:2020-12-13 22:36:37 所属栏目:百科 来源:网络整理
导读:简单的概率DP。因为输入顺序反了,。错了N次。,, 代码如下: #include iostream#include string.h#include math.h#include queue#include algorithm#include stdlib.h#include map#include set#include stdio.husing namespace std;#define LL __int64#def

简单的概率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("%.6fn",ans);
        }
        return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读