結果

問題 No.519 アイドルユニット
ユーザー uafr_csuafr_cs
提出日時 2017-11-08 15:35:22
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,185 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 134,188 KB
最終ジャッジ日時 2023-08-15 21:14:06
合計ジャッジ時間 6,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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; }
			
			for(int i = 0; i < n; i++){
				if((bit & (1 << i)) != 0) { continue; }
				
				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