結果

問題 No.65 回数の期待値の練習
ユーザー spaciaspacia
提出日時 2016-01-20 11:10:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 659 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 75,576 KB
実行使用メモリ 53,380 KB
最終ジャッジ日時 2023-10-21 13:28:56
合計ジャッジ時間 4,474 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
53,352 KB
testcase_01 AC 57 ms
53,368 KB
testcase_02 AC 56 ms
53,356 KB
testcase_03 AC 55 ms
53,380 KB
testcase_04 AC 56 ms
53,352 KB
testcase_05 AC 56 ms
53,364 KB
testcase_06 AC 56 ms
53,360 KB
testcase_07 AC 56 ms
52,236 KB
testcase_08 AC 57 ms
52,232 KB
testcase_09 AC 58 ms
53,360 KB
testcase_10 AC 57 ms
52,224 KB
testcase_11 AC 58 ms
52,400 KB
testcase_12 AC 56 ms
52,368 KB
testcase_13 AC 56 ms
52,236 KB
testcase_14 AC 57 ms
52,236 KB
testcase_15 AC 58 ms
52,244 KB
testcase_16 AC 57 ms
53,364 KB
testcase_17 AC 57 ms
52,268 KB
testcase_18 AC 57 ms
53,360 KB
testcase_19 AC 56 ms
52,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	static int k;
	static double[] memo;
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static double E (int x) {
		if (memo[x] != -1) return memo[x];
		if (x >= k) return memo[x] = 0;
		return memo[x] = (E(x + 1) + E(x + 2) + E(x + 3) + E(x + 4) + E(x + 5) + E(x + 6)) / 6.0 + 1;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		k = Integer.parseInt(br.readLine());
		memo = new double[k + 6];
		Arrays.fill(memo , -1);
		
		E(0);
		
		out(memo[0]);
	}
}
0