結果
問題 |
No.90 品物の並び替え
|
ユーザー |
|
提出日時 | 2018-11-28 13:11:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 640 ms / 5,000 ms |
コード長 | 795 bytes |
コンパイル時間 | 1,581 ms |
コンパイル使用メモリ | 170,012 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 20:30:05 |
合計ジャッジ時間 | 2,988 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> items(n); vector<int> front(m), back(m), score(m); for(int i = 0; i < m; i++) { cin >> front[i] >> back[i] >> score[i]; } for(int i = 0; i < n; i++) { items[i] = i; } int ans = 0; do{ int tmp = 0; for(int i = 0; i < m; i++) { int f = -1, b = -1; for(int j = 0; j < n; j++) { if(items[j] == front[i]) f = j; if(items[j] == back[i]) b = j; if(b > f && f > -1 && b > -1) { tmp += score[i]; break; } } } ans = max(tmp, ans); }while(next_permutation(items.begin(), items.end())); cout << ans << endl; return 0; }