結果
| 問題 | No.90 品物の並び替え |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-07 19:25:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 184 ms / 5,000 ms |
| コード長 | 1,053 bytes |
| 記録 | |
| コンパイル時間 | 3,588 ms |
| コンパイル使用メモリ | 77,424 KB |
| 実行使用メモリ | 41,632 KB |
| 最終ジャッジ日時 | 2024-06-11 16:08:24 |
| 合計ジャッジ時間 | 4,821 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Main2 p = new Main2();
}
public Main2() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
score = new int[n][n];
for(int i=0;i<m;i++)
score[sc.nextInt()][sc.nextInt()] =sc.nextInt();
solve(score);
}
private int[][] score;
private int isUsed;
private int[] a;
public void solve(int[][] score) {
isUsed = 0;
a = new int[score.length];
int res = rec(0);
System.out.println(res);
}
private int rec(int cur) {
if(cur==score.length)
return calc();
int res=0;
for(int i=0;i<score.length;i++){
if((isUsed & (1<<i))!=0)
continue;
isUsed += (1<<i);
a[cur] = i;
res = Math.max(res, rec(cur+1));
isUsed -= (1<<i);
}
return res;
}
private int calc(){
int res = 0;
for(int i=0;i<score.length;i++){
for(int j=i+1;j<score[i].length;j++){
res += score[a[i]][a[j]];
}
}
return res;
}
}