結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
|
提出日時 | 2016-08-02 04:39:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 5,000 ms |
コード長 | 812 bytes |
コンパイル時間 | 1,863 ms |
コンパイル使用メモリ | 166,096 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-06 23:32:55 |
合計ジャッジ時間 | 2,612 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define mp make_pair #define pb push_back #define fi first #define se second int main() { int n,m; cin >>n >>m; int s[14][14]={0}; rep(i,m) { int x,y,score; cin >>x >>y >>score; s[x][y]=score; } int dp[1<<14]={0}; rep(mask,1<<n) { rep(i,n) { if(mask>>i&1) continue; int add=0; rep(j,n) if(mask>>j&1) add+=s[j][i]; int nx=mask+(1<<i); dp[nx]=max(dp[nx], dp[mask]+add); } } cout << dp[(1<<n)-1] << endl; return 0; }