HDU 3076 ssworld VS DDD (機率DP),hdussworld

來源:互聯網
上載者:User

HDU 3076 ssworld VS DDD (機率DP),hdussworld

簡單的機率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;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.