結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
kuramu
|
| 提出日時 | 2016-01-23 21:36:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,469 bytes |
| コンパイル時間 | 2,295 ms |
| コンパイル使用メモリ | 77,728 KB |
| 実行使用メモリ | 52,756 KB |
| 最終ジャッジ日時 | 2024-09-21 15:06:32 |
| 合計ジャッジ時間 | 3,981 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 9 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
static int[][] score;
static int N;
static int[] num;
static boolean[] check;
static int max;
public static void main(String[] args) {
BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
try {
String[] temps = stdReader.readLine().split(" ");
N = Integer.parseInt(temps[0]);
int m = Integer.parseInt(temps[1]);
score = new int[N][N];
for(int i=0;i<N;i++){
Arrays.fill(score[i], 0);
}
num = new int[N];
Arrays.fill(num, -1);
check = new boolean[N];
for(int i=0;i<m;i++){
String[] temps2 = stdReader.readLine().split(" ");
int item1 = Integer.parseInt(temps2[0]);
int item2 = Integer.parseInt(temps2[1]);
score[item1][item2] = Math.max(score[item1][item2], Integer.parseInt(temps2[2]));
}
solve(0);
System.out.println(max);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void getAns(){
int ans = 0;
for(int i=0;i<N-1;i++){
ans += score[num[i]][num[i+1]];
}
max = Math.max(max, ans);
}
public static void solve(int n){
if(n == N) {
getAns();
}else{
for(int i=0;i<N;i++){
if(!check[i]){
check[i] = true;
num[n] = i;
solve(n+1);
num[n] = -1;
check[i] = false;
}
}
}
}
}
kuramu