結果
問題 |
No.90 品物の並び替え
|
ユーザー |
|
提出日時 | 2017-03-08 11:35:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 828 bytes |
コンパイル時間 | 1,495 ms |
コンパイル使用メモリ | 161,876 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 18:43:22 |
合計ジャッジ時間 | 2,121 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,first,last) for (int i=first;i<last;++i) #define MAX(x,y) (x > y ? x : y) #define MIN(x,y) (x < y ? x : y) int N, M; int scores[10][10]; vector<int> nums; vector<int> made; vector<int> fl(9, 0); int ans = 0; void solve(int cnt){ if (cnt >= N) { int sum = 0; REP(i,0,N-1){ REP(j,i+1,N){ sum += scores[made[i]][made[j]]; } } ans = MAX(sum, ans); return; } REP(i,0,N){ if (fl[i] != 1) { fl[i] = 1; made.push_back(nums[i]); solve(cnt + 1); made.pop_back(); fl[i] = 0; } } } int main(){ cin >> N >> M; REP(i,0,N){ nums.push_back(i); } int it_1, it_2, s; REP(i,0,M){ cin >> it_1 >> it_2 >> s; scores[it_1][it_2] = s; } solve(0); cout << ans << endl; }