結果

問題 No.58 イカサマなサイコロ
ユーザー リチウムリチウム
提出日時 2014-11-05 02:11:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 879 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 73,788 KB
実行使用メモリ 56,280 KB
最終ジャッジ日時 2023-08-29 00:41:01
合計ジャッジ時間 3,884 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,280 KB
testcase_01 AC 125 ms
55,832 KB
testcase_02 AC 120 ms
55,796 KB
testcase_03 AC 122 ms
56,092 KB
testcase_04 AC 121 ms
56,184 KB
testcase_05 AC 121 ms
55,468 KB
testcase_06 AC 121 ms
56,148 KB
testcase_07 AC 122 ms
56,208 KB
testcase_08 AC 121 ms
56,036 KB
testcase_09 AC 115 ms
55,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		double dp[][]=new double [n+1][n*6+1];
		double dp2[][]=new double[n+1][n*6+1];
		Arrays.fill(dp[0],0);
		Arrays.fill(dp2[0],0);
		dp[0][0]=1;
		dp2[0][0]=1;
		for(int i=1;i<=n;i++){
			for(int j=0;j<n*6+1;j++){
				for(int p=j-6;p<j;p++){
					if(p>=0){
						dp[i][j]+=dp[i-1][p]/6;
					}
				}
				if(i<=k){
					for(int p=j-6;p<j-3;p++){
						if(p>=0)dp2[i][j]+=dp2[i-1][p]/3;
					}
				}
					else{
						for(int p=j-6;p<j;p++){
							if(p>=0){
								dp2[i][j]+=dp2[i-1][p]/6;
							}
					}
				}
			}
		}
		double ans=0;
		for(int i=0;i<n*6+1;i++){
			for(int j=i+1;j<n*6+1;j++){
				ans+=dp[n][i]*dp2[n][j];
			}
		}
		System.out.println(ans);
		
		}
}
0