結果
| 問題 | No.357 品物の並び替え (Middle) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-06-08 05:12:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 5,000 ms | 
| コード長 | 693 bytes | 
| コンパイル時間 | 668 ms | 
| コンパイル使用メモリ | 72,064 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-11 01:04:18 | 
| 合計ジャッジ時間 | 1,434 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 | 
ソースコード
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
template <class T> bool setmax(T & l, T const & r) { if (not (l < r)) return false; l = r; return true; }
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > score(n, vector<int>(n));
    repeat (i,m) {
        int x, y, z; cin >> x >> y >> z;
        score[x][y] = z;
    }
    vector<int> dp(1<<n);
    repeat (s,1<<n) {
        repeat (i,n) if (not (s & (1<<i))) {
            int acc = dp[s];
            repeat (j,n) if (s & (1<<j)) acc += score[j][i];
            setmax(dp[s | (1<<i)], acc);
        }
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}
            
            
            
        