結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 2018-08-23 22:06:24 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 143 ms / 5,000 ms |
コード長 | 1,017 bytes |
コンパイル時間 | 944 ms |
コンパイル使用メモリ | 76,280 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 05:03:40 |
合計ジャッジ時間 | 1,777 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <iostream>#include <vector>#include <unordered_set>using namespace std;int max_score=-1;void proc(int i, int n, vector<int>& buf, unordered_set<int>& selected, vector<vector<int>>& map){if(i>=n){int score=0;for(int j=0; j<n; ++j){for(int k=j+1; k<n; ++k){score+=map[buf[j]][buf[k]];}}max_score=max(score, max_score);} else{for(int j=0; j<n; ++j){if(selected.find(j)!=selected.end()) continue;selected.insert(j);buf[i]=j;proc(i+1, n, buf, selected, map);selected.erase(j);}}}int main(){int n, m;cin >> n >> m;vector<vector<int>> map(n, vector<int>(n, 0));for(int i=0; i<m; ++i){int i1, i2, s;cin >> i1 >> i2 >> s;map[i1][i2]=s;}vector<int> buf(n);unordered_set<int> selected;proc(0, n, buf, selected, map);cout << max_score << endl;return 0;}