結果
問題 |
No.90 品物の並び替え
|
ユーザー |
![]() |
提出日時 | 2019-04-16 14:47:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 769 bytes |
コンパイル時間 | 1,673 ms |
コンパイル使用メモリ | 173,248 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 08:15:21 |
合計ジャッジ時間 | 2,171 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 9 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long int G[10][10]; signed 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,c; cin >> a >> b >> c; G[a][b] = c; } int ans = 0; vector< vector<int> > dp(1 << n,vector<int> (n,-1)); function< int(int,int) > rec = [&](int S,int u){ if(__builtin_popcount(S) == n) return 0LL; if(dp[S][u] != -1) return dp[S][u]; int res = 0; for(int i = 0; i < n; i++){ if(S == 0){ res = max(res,rec(S | 1 << i,i)); } else if(!(S >> i & 1) && G[u][i]){ res = max(res,rec(S | 1 << i,i) + G[u][i]); } } return dp[S][u] = res; }; cout << rec(0,0) << endl; return 0; }