結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
![]() |
提出日時 | 2017-11-24 23:53:53 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 8 ms / 5,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 520 ms |
コンパイル使用メモリ | 66,532 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 08:35:51 |
合計ジャッジ時間 | 1,144 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <utility>using namespace std;typedef pair<int, int> P;typedef unsigned long long ll;const int inf = 999999999;const int mod = 1000000007;int dp[1 << 14];int main(){int n, m;cin >> n >> m;int d[n][n];for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){d[i][j] = 0;}}for(int i = 0; i < m; i++){int x, y, z;cin >> x >> y >> z;d[x][y] = z;}for(int S = 0; S < (1 << n); S++){for(int i = 0; i < n; i++){if((S & (1 << i)) == 0){int t = 0;for(int j = 0; j < n; j++){if(S & (1 << j)){t += d[j][i];}}dp[S | (1 << i)] = max(dp[S | (1 << i)], dp[S] + t);}}}cout << dp[(1 << n) - 1] << endl;return 0;}