結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
![]() |
提出日時 | 2019-06-22 19:45:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,104 bytes |
コンパイル時間 | 975 ms |
コンパイル使用メモリ | 108,268 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-26 09:44:43 |
合計ジャッジ時間 | 1,858 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 17 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <list> #include <set> #include <map> #include <numeric> #include <regex> #include <tuple> #include<iomanip> using namespace std; typedef long long ll; typedef pair<int, int> P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 int dp[1 << 14]; vector<vector<P>> V(14); int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; for (int i = 0; i < M; i++) { int a, b, val; cin >> a >> b >> val; V[b].push_back(P(a, val)); // bより前にaがあれば価値が+val } for (int i = 0; i < (1 << N); i++) { for (int nxt = 0; nxt < N; nxt++) { if (!(1 & (i >> nxt))) { // nxtが未使用なら int addval = 0; //後ろにnxtを加えることで生じる追加価値 for (int k = 0; k < V[nxt].size(); k++) { if (1 & (i >> V[nxt][k].first)) addval += V[nxt][k].second; } dp[i + (1 << nxt)] = max(dp[1 << nxt], dp[i] + addval); } } } cout << dp[(1 << N) - 1] << endl; return 0; }