結果

問題 No.162 8020運動
ユーザー kenkooookenkoooo
提出日時 2015-03-07 02:23:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 1,456 bytes
コンパイル時間 4,714 ms
コンパイル使用メモリ 73,560 KB
実行使用メモリ 56,256 KB
最終ジャッジ日時 2023-09-06 20:34:21
合計ジャッジ時間 12,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,640 KB
testcase_01 AC 188 ms
55,764 KB
testcase_02 AC 208 ms
56,256 KB
testcase_03 AC 236 ms
56,044 KB
testcase_04 AC 236 ms
55,464 KB
testcase_05 AC 231 ms
55,676 KB
testcase_06 AC 233 ms
55,976 KB
testcase_07 AC 246 ms
55,448 KB
testcase_08 AC 239 ms
55,772 KB
testcase_09 AC 136 ms
56,076 KB
testcase_10 AC 211 ms
55,812 KB
testcase_11 AC 188 ms
55,732 KB
testcase_12 AC 166 ms
55,832 KB
testcase_13 AC 235 ms
55,628 KB
testcase_14 AC 136 ms
56,040 KB
testcase_15 AC 133 ms
55,684 KB
testcase_16 AC 169 ms
56,048 KB
testcase_17 AC 153 ms
55,940 KB
testcase_18 AC 229 ms
55,648 KB
testcase_19 AC 210 ms
55,528 KB
testcase_20 AC 216 ms
55,536 KB
testcase_21 AC 218 ms
55,820 KB
testcase_22 AC 207 ms
55,716 KB
testcase_23 AC 217 ms
55,896 KB
testcase_24 AC 207 ms
55,728 KB
testcase_25 AC 224 ms
55,756 KB
testcase_26 AC 132 ms
55,940 KB
testcase_27 AC 192 ms
55,712 KB
testcase_28 AC 228 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}

}
0