結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
![]() |
提出日時 | 2019-01-31 16:46:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 5,000 ms |
コード長 | 804 bytes |
コンパイル時間 | 1,945 ms |
コンパイル使用メモリ | 198,764 KB |
最終ジャッジ日時 | 2025-01-06 20:42:01 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include<bits/stdc++.h>using namespace std;using Int = long long;template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}//INSERT ABOVE HEREsigned main(){Int n,m;cin>>n>>m;vector<Int> x(m),y(m),z(m);for(Int i=0;i<m;i++) cin>>x[i]>>y[i]>>z[i];Int s=1<<n;vector<vector<Int> > sc(n,vector<Int>(s,0));for(Int i=0;i<n;i++){for(Int b=0;b<s;b++){for(Int j=0;j<m;j++){if(y[j]!=i) continue;if((b>>x[j])&1) sc[i][b]+=z[j];}}}vector<Int> dp(s,0);for(Int b=0;b<s;b++){for(Int i=0;i<n;i++){if((b>>i)&1) continue;chmax(dp[b|(1<<i)],dp[b]+sc[i][b]);}}cout<<*max_element(dp.begin(),dp.end())<<endl;return 0;}