結果

問題 No.161 制限ジャンケン
ユーザー kou6839
提出日時 2015-03-11 22:28:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 426 ms / 5,000 ms
コード長 1,287 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 79,388 KB
実行使用メモリ 68,756 KB
最終ジャッジ日時 2024-11-30 04:29:42
合計ジャッジ時間 7,558 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.beans.IntrospectionException;
import java.util.*;

class Main {
	static int jan(int g,int c,int p){
		if(g==0 && c ==0 && p==0)return 0;
		if(dp[g][c][p]>0)return dp[g][c][p];
		int res = 0;
		if(g>0){
			res = Math.max(res, jan(g-1, c, p)+ja[gu][Integer.parseInt(te.charAt(te.length()-g-c-p)+"")]);
		}
		if(c>0){
			res = Math.max(res, jan(g, c-1, p)+ja[tyo][Integer.parseInt(te.charAt(te.length()-g-c-p)+"")]);
		}
		if(p>0){
			res = Math.max(res, jan(g, c, p-1)+ja[pa][Integer.parseInt(te.charAt(te.length()-g-c-p)+"")]);
		}
		return dp[g][c][p]=res;
		
	}
	static int[][][] dp;
	static int gu = 0;
	static int tyo = 1;
	static int pa = 2;
	static int[][] ja = new int[3][3];
	static String te;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int g = sc.nextInt();
		int c = sc.nextInt();
		int p = sc.nextInt();
		String temp = sc.next();
		for(int i=0;i<temp.length();i++){
			if(temp.charAt(i)=='G'){
				te+=0;
			}else if(temp.charAt(i)=='C'){
				te+=1;
				
			}else{
				te+=2;
			}
		}
		int ans =0 ;
		ja[gu][gu]=1;
		ja[gu][tyo]=3;
		ja[gu][pa]=0;
		ja[tyo][gu]=0;
		ja[tyo][tyo]=1;
		ja[tyo][pa]=3;
		ja[pa][gu]=3;
		ja[pa][tyo]=0;
		ja[pa][pa]=1;
		dp = new int[g+1][c+1][p+1];
		System.out.println(jan(g, c, p));
	}
}
0