結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2014-12-07 19:11:25 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 212 ms / 5,000 ms |
| コード長 | 1,090 bytes |
| コンパイル時間 | 2,154 ms |
| コンパイル使用メモリ | 77,416 KB |
| 実行使用メモリ | 41,880 KB |
| 最終ジャッジ日時 | 2024-06-11 16:06:38 |
| 合計ジャッジ時間 | 4,541 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
package no090;
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();
int[][] score = new int[n][n];
for(int i=0;i<m;i++) {
int item1 = sc.nextInt();
int item2 = sc.nextInt();
int s = sc.nextInt();
score[item1][item2] = s;
}
int[] p = new int[n];
for(int i=0;i<n;i++) {
p[i] = i;
}
int max = 0;
do {
int sum = 0;
for(int i=0;i<n;i++) {
for(int j=i+1;j<n;j++) {
sum += score[p[i]][p[j]];
}
}
max = Math.max(max,sum);
} while (nextPermutation(p));
System.out.println(max);
}
static boolean nextPermutation(int[] p) {
for(int a=p.length-2;a>=0;--a) {
if(p[a]<p[a+1]) {
for(int b=p.length-1;;--b) {
if(p[b]>p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for(++a, b=p.length-1;a<b;++a,--b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
}
}
return false;
}
}
ぴろず