結果

問題 No.162 8020運動
ユーザー motimoti
提出日時 2015-04-14 12:25:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,231 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 53,392 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 20:12:04
合計ジャッジ時間 3,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 48 ms
4,376 KB
testcase_02 AC 72 ms
4,380 KB
testcase_03 AC 97 ms
4,376 KB
testcase_04 AC 97 ms
4,376 KB
testcase_05 AC 98 ms
4,376 KB
testcase_06 AC 97 ms
4,380 KB
testcase_07 AC 97 ms
4,380 KB
testcase_08 AC 98 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 73 ms
4,376 KB
testcase_11 AC 49 ms
4,380 KB
testcase_12 AC 24 ms
4,376 KB
testcase_13 AC 98 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 29 ms
4,376 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 92 ms
4,380 KB
testcase_19 AC 68 ms
4,376 KB
testcase_20 AC 78 ms
4,380 KB
testcase_21 AC 79 ms
4,380 KB
testcase_22 AC 73 ms
4,380 KB
testcase_23 AC 78 ms
4,376 KB
testcase_24 AC 73 ms
4,376 KB
testcase_25 AC 83 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 54 ms
4,376 KB
testcase_28 AC 93 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <assert.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

double P[3];
double dp[22][15];

double solve(int depth, int num) {

    if(depth == 0) { return num; }

    double& ret = dp[depth][num];
    if(ret >= 0) { return ret; }

    if(num == 1) { return ret = solve(depth-1, 1)*(1.0-P[0]); }

    ret = 0.;
    rep(S, 1<<num) {
        double prob = 1.0;
        rep(i, num) {
            double bad = (i==0||i==num-1) ? P[1] : P[2];
            if(S & (1<<i))  { prob *= 1.0-bad;  }
            else            { prob *= bad;      }
        }

        int next_num = 0;
        rep(i, num) {
            if(S & (1<<i)) {
                next_num ++;
            }
            else {
                if(next_num) {
                    ret += solve(depth-1, next_num) * prob;
                }
                next_num = 0;
            }
        }
        if(next_num) {
            ret += solve(depth-1, next_num) * prob;
        }
    }
    return ret;
}

int main() {
    int year; cin >> year;
    rep(i, 3) { cin >> P[i]; P[i] /= 100.0; }
    rep(i, 22) rep(j, 15) { dp[i][j] = -1.0; }
    printf("%.9lf\n", solve(80-year, 14) * 2.0);
    return 0;
}
0