結果

問題 No.519 アイドルユニット
ユーザー uafr_csuafr_cs
提出日時 2017-11-08 15:37:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 304 ms / 1,000 ms
コード長 1,148 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 78,368 KB
実行使用メモリ 109,788 KB
最終ジャッジ日時 2024-05-03 07:48:10
合計ジャッジ時間 10,275 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 295 ms
109,552 KB
testcase_01 AC 304 ms
109,684 KB
testcase_02 AC 231 ms
59,788 KB
testcase_03 AC 177 ms
42,624 KB
testcase_04 AC 132 ms
40,944 KB
testcase_05 AC 141 ms
41,204 KB
testcase_06 AC 139 ms
41,076 KB
testcase_07 AC 143 ms
41,412 KB
testcase_08 AC 148 ms
41,292 KB
testcase_09 AC 151 ms
41,868 KB
testcase_10 AC 155 ms
41,964 KB
testcase_11 AC 180 ms
42,844 KB
testcase_12 AC 134 ms
41,328 KB
testcase_13 AC 174 ms
42,800 KB
testcase_14 AC 173 ms
42,716 KB
testcase_15 AC 178 ms
42,568 KB
testcase_16 AC 177 ms
42,800 KB
testcase_17 AC 182 ms
43,340 KB
testcase_18 AC 176 ms
42,912 KB
testcase_19 AC 170 ms
42,460 KB
testcase_20 AC 177 ms
42,652 KB
testcase_21 AC 171 ms
42,444 KB
testcase_22 AC 178 ms
43,036 KB
testcase_23 AC 179 ms
42,936 KB
testcase_24 AC 207 ms
46,048 KB
testcase_25 AC 216 ms
45,760 KB
testcase_26 AC 223 ms
46,060 KB
testcase_27 AC 200 ms
45,856 KB
testcase_28 AC 224 ms
46,252 KB
testcase_29 AC 295 ms
109,608 KB
testcase_30 AC 302 ms
109,496 KB
testcase_31 AC 293 ms
109,788 KB
testcase_32 AC 302 ms
109,716 KB
testcase_33 AC 132 ms
40,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static int solve_DP(int n, int[][] adj){
		int[] DP = new int[1 << n];
		final int INF = Integer.MAX_VALUE / 2 - 1;
		Arrays.fill(DP, INF);
		DP[0] = 0;
		
		for(int bit = 0; bit < (1 << n); bit++){
			if(DP[bit] >= INF){ continue; }
			
			int i = 0;
			for(; (bit & (1 << i)) != 0; i++);
			
			final int fst = 1 << i;
			for(int j = i + 1; j < n; j++){
				if((bit & (1 << j)) != 0){ continue; }
				
				final int snd = 1 << j;
				final int next_bit = bit | fst | snd;
				DP[next_bit] = Math.min(DP[next_bit], DP[bit] + adj[i][j]);
			}
		}
		
		return DP[(1 << n) - 1];
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		final int max = 1000;
		int[][] adj = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				adj[i][j] = max - sc.nextInt();
			}
		}
		
		final int solve = solve_DP(n, adj);
		
		System.out.println(max * (n / 2) - solve);
	}
}
0