結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-19 22:28:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 459 bytes |
| コンパイル時間 | 1,844 ms |
| コンパイル使用メモリ | 170,256 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-16 02:14:54 |
| 合計ジャッジ時間 | 2,534 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
int dp[1<<14];
vector<P>v[14];
int main(){
int n,m;scanf("%d%d",&n,&m);
rep(i,m){
int a,b,c;scanf("%d%d%d",&a,&b,&c);
v[b].push_back(P(c,a));
}
rep(i,1<<n){
rep(j,n){
if(i>>j&1)continue;
int cnt=0;
for(P k:v[j]){
if(i>>k.second&1)cnt+=k.first;
}
dp[i|1<<j]=max(dp[i|1<<j],dp[i]+cnt);
}
}
cout<<dp[(1<<n)-1]<<endl;
}