結果
問題 | No.90 品物の並び替え |
ユーザー |
|
提出日時 | 2014-12-08 21:18:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 680 ms / 5,000 ms |
コード長 | 1,254 bytes |
コンパイル時間 | 3,031 ms |
コンパイル使用メモリ | 77,900 KB |
実行使用メモリ | 55,200 KB |
最終ジャッジ日時 | 2024-06-11 18:30:02 |
合計ジャッジ時間 | 5,527 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
import java.util.Scanner;public class Yukicoder90 {static int n, m, buf, max = -1;static int[] item;static int[][] score;static boolean cover = false;public static void main(String[] args) {Scanner sc = new Scanner(System.in);n = sc.nextInt();m = sc.nextInt();item = new int[n];score = new int[m][3];for (int i = 0; i < m; i++) {for (int j = 0; j < 3; j++) {score[i][j] = sc.nextInt();}}// 全探索uwaaaaa(0);System.out.println(max);}static void uwaaaaa(int now) {if (now == n) {buf = 0;for (int i = 0; i < m; i++) {if (compereIndex(score[i][0], score[i][1])) {buf += score[i][2];}}max = Math.max(max, buf);return;}for (int i = 0; i < n; i++) {cover = true;for (int j = 0; j < now; j++) {if (now != 0 && i == item[j]) {cover = false;break;}}if (cover) {item[now] = i;uwaaaaa(now + 1);}}}static boolean compereIndex(int a, int b) {int aPos = 0, bPos = 0;for (int i = 0; i < n; i++) {if (a == item[i]) aPos = i;if (b == item[i]) bPos = i;}if (aPos < bPos) return true;else return false;}}