結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 2015-08-17 21:56:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 129 ms / 5,000 ms |
コード長 | 1,130 bytes |
コンパイル時間 | 2,125 ms |
コンパイル使用メモリ | 77,408 KB |
実行使用メモリ | 52,776 KB |
最終ジャッジ日時 | 2024-07-18 10:03:31 |
合計ジャッジ時間 | 2,953 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
import java.io.*;import java.util.Arrays;class Main{static final PrintWriter out=new PrintWriter(System.out);static final int INF=Integer.MIN_VALUE/2;public static void main(String[] args) throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));String line=br.readLine();int n=Integer.parseInt(line.split(" ")[0]);int m=Integer.parseInt(line.split(" ")[1]);int[][] score=new int[n][n];int[] a=new int[n];while(m-->0){line=br.readLine();int x=Integer.parseInt(line.split(" ")[0]);int y=Integer.parseInt(line.split(" ")[1]);score[x][y]=Integer.parseInt(line.split(" ")[2]);}for(int i=0;i<n;i++) a[i]=i;int ans=0;do{int cnt=0;for(int i=0;i<n-1;i++){for(int j=i+1;j<n;j++){cnt+=score[a[i]][a[j]];}}ans=Math.max(ans,cnt);}while(next_permutation(a));out.println(ans);out.flush();}public static boolean next_permutation(int[] a){for(int i=a.length-2;i>=0;i--){if(a[i]<a[i+1]){for(int j=a.length-1;;j--){if(a[i]<a[j]){int temp=a[i]; a[i]=a[j]; a[j]=temp;for(i++,j=a.length-1;i<j;i++,j--){temp=a[i]; a[i]=a[j]; a[j]=temp;}return true;}}}}return false;}}