結果

問題 No.108 トリプルカードコンプ
ユーザー 37zigen37zigen
提出日時 2016-05-19 12:18:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 188 ms / 5,000 ms
コード長 2,635 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 79,160 KB
実行使用メモリ 52,556 KB
最終ジャッジ日時 2024-04-15 23:10:25
合計ジャッジ時間 6,675 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,596 KB
testcase_01 AC 135 ms
41,620 KB
testcase_02 AC 131 ms
41,324 KB
testcase_03 AC 130 ms
41,260 KB
testcase_04 AC 134 ms
41,284 KB
testcase_05 AC 128 ms
41,372 KB
testcase_06 AC 129 ms
41,540 KB
testcase_07 AC 185 ms
52,112 KB
testcase_08 AC 186 ms
52,184 KB
testcase_09 AC 167 ms
52,184 KB
testcase_10 AC 166 ms
52,472 KB
testcase_11 AC 158 ms
52,092 KB
testcase_12 AC 130 ms
41,432 KB
testcase_13 AC 162 ms
42,456 KB
testcase_14 AC 154 ms
42,260 KB
testcase_15 AC 150 ms
42,112 KB
testcase_16 AC 149 ms
42,568 KB
testcase_17 AC 141 ms
42,048 KB
testcase_18 AC 182 ms
52,412 KB
testcase_19 AC 187 ms
52,556 KB
testcase_20 AC 181 ms
52,484 KB
testcase_21 AC 188 ms
52,312 KB
testcase_22 AC 181 ms
52,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	//memo[i][j][k]:0枚のカードがi種類,1枚のカードがj種類,2枚のカードがk種類の状態から、完了まで引く回数の期待値
	double memo[][][];
	int N;
	void solve(){
		double time=System.currentTimeMillis();
		Scanner sc=new Scanner(System.in);
		N=sc.nextInt();
		int[] A=new int[N];

		int sum_0=0;//0枚のカードの種類数
		int sum_1=0;//1枚のカードの種類数
		int sum_2=0;//2枚のカードの種類数
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
			if(A[i]==0)sum_0++;
			else if(A[i]==1)sum_1++;
			else if(A[i]==2)sum_2++;
		}
		memo=new double[N+1][N+1][N+1];
		for(int i=0;i<N+1;i++)for(int j=0;j<N+1;j++)for(int k=0;k<N+1;k++)
			memo[i][j][k]=-1;
		memo[0][0][0]=0;
		double ans=dp(sum_0,sum_1,sum_2);
		System.out.println(ans);
		//p[i][j][k]=0枚のカードがi種類,1枚のカードがj種類,2枚のカードがk種類の状態になる確率。
		//		double[][][] from=new double[N+1][N+1][N+1];
		//		double[][][] to=new double[N+1][N+1][N+1];
		//		from[sum_0][sum_1][sum_2]=1;
		//e:期待値
		//		double e=0;
		//		for(int t=1;t<=3000;t++){
		//			for(int i=0;i<N+1;i++){
		//				for(int j=0;j+i<N+1;j++){
		//					for(int k=0;k+i+j<N+1;k++){
		//						//						tr(from);
		//						//						System.out.println();
		//						to[i][j][k]+=from[i][j][k]*((double)(N-i-j-k)/(double)N);
		//						if(i>=1){
		//							to[i-1][j+1][k]+=from[i][j][k]*((double)i/(double)N);
		//						}
		//						if(j>=1){
		//							to[i][j-1][k+1]+=from[i][j][k]*((double)j/(double)N);
		//						}
		//						if(k>=1){
		//							if(i==0&&j==0&&k==1)
		//								e+=t*from[i][j][k]*((double)k/(double)N);
		//							to[i][j][k-1]+=from[i][j][k]*((double)k/(double)N);
		//						}
		//					}
		//				}
		//			}
		//			from=to;double[][][] d=new double[N+1][N+1][N+1];
		//			to=d;
		//		}
		System.err.println(System.currentTimeMillis()-time);
	}
	void tr(double[][][] p){
		int n=p.length;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					System.out.println(i+" "+j+" "+k+" "+p[i][j][k]);
				}
			}
		}
	}
	double dp(int i,int j,int k){
		if(memo[i][j][k]!=-1)return memo[i][j][k];
		int res=i+j+k;
		if(res==0)return 0;
		else{
			double e=((double)N)/((double)res);
			double ret=e;
			if(i>=1){
				ret+=dp(i-1,j+1,k)*((double)i/((double)res));
			}
			if(j>=1){
				ret+=dp(i,j-1,k+1)*((double)j/((double)res));
			}
			if(k>=1){
				ret+=dp(i,j,k-1)*((double)k/(double)res);
			}
			memo[i][j][k]=ret;
			return ret;
		}
	}
}
0