結果

問題 No.324 落ちてた閉路グラフ
ユーザー 37zigen37zigen
提出日時 2016-03-21 13:56:58
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,847 bytes
コンパイル時間 2,442 ms
コンパイル使用メモリ 79,544 KB
実行使用メモリ 169,516 KB
最終ジャッジ日時 2024-04-08 21:20:43
合計ジャッジ時間 10,442 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
59,388 KB
testcase_01 AC 214 ms
59,492 KB
testcase_02 AC 214 ms
59,492 KB
testcase_03 AC 214 ms
59,384 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Date;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();//m頂点の誘導部分グラフ
		int[] w=new int[n];
		for(int i=0;i<n;i++){
			w[i]=sc.nextInt();
		}
		long t=new Date().getTime();
		int inf=-1000000;
		System.err.println(new Date().getTime()-t+"ms");
		int[][][][] dp=new int[2][2][m+1][n+1];
		System.err.println(new Date().getTime()-t+"ms");
		//dp[0番目の頂点を拾ったかどうか0:拾わず/1:拾った][i番目まで確定][頂点数][i番目の頂点を拾ったか(0:拾わず/1:拾った)]=その時点での最大価値
		for(int i=0;i<2;i++){//2*n*k*l=2*6*3*2=72
			for(int l=0;l<2;l++){
				for(int k=0;k<=m;k++){
					for(int j=1;j<n;j++){
						dp[i][l][k][j]=inf;
					}
				}
			}
		}
		System.err.println(new Date().getTime()-t+"ms");
		for(int i=0;i<2;i++){
			for(int j=1;j<=n;j++){
				for(int k=0;k<=j&&k<=m;k++){
					for(int l=0;l<2;l++){
						if(k<l||k<i||(j!=n&&j+i-1+l-1<k)){
							continue;
						}else if(l==0&&j>1){
							dp[i][l][k][j]=Math.max(dp[i][0][k][j-1], dp[i][1][k][j-1]);
						}else if(l==1&&j>1){
							dp[i][l][k][j]=Math.max(dp[i][0][k-1][j-1], dp[i][1][k-1][j-1]+w[j-2]);
						}else if(j==1){
							dp[i][l][k][j]=0;
						}else{
							System.err.println("Error dp["+i+"]["+l+"]["+k+"]["+j+"]="+dp[i][l][k][j]);
						}
					}
				}
			}
		}
		for(int i=0;i<2;i++){
			for(int j=1;j<=n;j++){
				for(int k=0;k<=m;k++){
					for(int l=0;l<2;l++){
						System.err.println("dp["+i+"]["+l+"]["+k+"]["+j+"]="+dp[i][l][k][j]);
					}
				}
			}
		}
		int max;
		max=Math.max(dp[0][0][m][n],dp[0][1][m][n]);
		max=Math.max(dp[1][0][m][n],dp[1][1][m][n]+w[n-1]);
		System.out.println(max);
		System.err.println(new Date().getTime()-t+"ms");
	}
}
0