結果
問題 | No.162 8020運動 |
ユーザー |
![]() |
提出日時 | 2015-04-14 12:25:23 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 83 ms / 5,000 ms |
コード長 | 1,231 bytes |
コンパイル時間 | 484 ms |
コンパイル使用メモリ | 58,288 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 14:24:56 |
合計ジャッジ時間 | 2,821 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#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; }