結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
![]() |
提出日時 | 2018-03-06 13:27:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 5,000 ms |
コード長 | 1,002 bytes |
コンパイル時間 | 975 ms |
コンパイル使用メモリ | 72,404 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 20:59:29 |
合計ジャッジ時間 | 1,564 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; typedef long long i64; typedef long double ld; typedef pair<i64,i64> P; #define rep(i,s,e) for(int i = (s);i <= (e);i++) int n; int m; const int MAX = (1 << 15); int dp[MAX]; int score[20][20]; int main() { cin >> n >> m; rep(i,0,m - 1) { int a,b,s; cin >> a >> b >> s; score[a][b] = s; } rep(i,0,(1 << n) - 1) { rep(j,0,n - 1) { if((1 << j) & i) { int sub = i & ~(1 << j); int res = 0; rep(k,0,n - 1) { if(sub & (1 << k)) { res += score[k][j]; } } dp[i] = max(dp[i] , dp[sub] + res); } } } cout << dp[(1 << n) - 1] << endl; }