結果
| 問題 |
No.162 8020運動
|
| コンテスト | |
| ユーザー |
kenkoooo
|
| 提出日時 | 2015-03-07 02:23:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 285 ms / 5,000 ms |
| コード長 | 1,456 bytes |
| コンパイル時間 | 3,213 ms |
| コンパイル使用メモリ | 77,152 KB |
| 実行使用メモリ | 54,488 KB |
| 最終ジャッジ日時 | 2024-06-24 14:57:01 |
| 合計ジャッジ時間 | 10,459 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
double p0 = sc.nextInt() / 100.0;
double p1 = sc.nextInt() / 100.0;
double p2 = sc.nextInt() / 100.0;
sc.close();
int n = 80 - a;
double[][] dp = new double[n + 1][15];
for (int i = 0; i < 15; i++) {
dp[0][i] = i;
}
for (int year = 1; year <= n; year++) {
for (int tooth = 1; tooth < 15; tooth++) {
for (int bit = 0; bit < 1 << tooth; bit++) {
/*
* 1<<toothからbitに遷移する確率pを計算する
*/
double p = 1;
for (int t = 0; t < tooth; t++) {
boolean injured = ((bit >> t & 1) == 1);// 歯tが抜けていればtrue
int count = (t == 0 ? 0 : 1) + (t == tooth - 1 ? 0 : 1);
if (count == 0) {
// 両隣が抜歯済み
p *= injured ? p0 : 1 - p0;
} else if (count == 1) {
// 片側が抜歯済み
p *= injured ? p1 : 1 - p1;
} else {
// 両隣が生えてる
p *= injured ? p2 : 1 - p2;
}
}
double sum = 0;
int seq = 0;
for (int l = 0; l <= tooth; l++) {
if ((bit >> l & 1) == 0 && (l < tooth)) {
seq++;
} else {
sum += dp[year - 1][seq];
seq = 0;
}
}
dp[year][tooth] += p * sum;
}
}
}
// System.out.println(Arrays.deepToString(dp));
System.out.println(dp[n][14] * 2);
}
}
kenkoooo