HDU 3853 LOOPS 機率dp(水,hdu3853

來源:互聯網
上載者:User

HDU 3853 LOOPS 機率dp(水,hdu3853

水水過~



#include <stdio.h>#include <cstring>#include <iostream>#include <map>#include <cmath>template <class T>inline bool rd(T &ret) {    char c; int sgn;    if(c=getchar(),c==EOF) return 0;    while(c!='-'&&(c<'0'||c>'9')) c=getchar();    sgn=(c=='-')?-1:1;    ret=(c=='-')?0:(c-'0');    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');    ret*=sgn;    return 1;}template <class T>inline void pt(T x) {    if (x <0) {        putchar('-');        x = -x;    }    if(x>9) pt(x/10);    putchar(x%10+'0');}using namespace std;typedef unsigned long long ull;const double eps = 1e-10;const int N = 1005;int n, m;double mp[N][N][3], dp[N][N];double solve(){dp[n][m] = 0;for(int i = n; i ; i--)for(int j = m; j; j--){if(i == n && j == m)continue;if(fabs(mp[i][j][0] - 1.0) < eps){dp[i][j] = 0;}else{dp[i][j] = mp[i][j][1] * dp[i][j+1] + mp[i][j][2] * dp[i+1][j];dp[i][j] += 2.0;dp[i][j] /= (1 - mp[i][j][0]);}}return dp[1][1];}void input(){for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++)scanf("%lf %lf %lf", &mp[i][j][0], &mp[i][j][1], &mp[i][j][2]);}int main(){    while(cin>>n>>m){        input();        printf("%.3f\n", solve());    }    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.