結果
問題 | No.733 分身並列コーディング |
ユーザー |
![]() |
提出日時 | 2018-09-07 21:26:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,140 ms / 1,500 ms |
コード長 | 766 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 172,032 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-11-29 05:22:09 |
合計ジャッジ時間 | 23,871 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#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 HERE signed main(){ Int t,n; cin>>t>>n; vector<Int> x(n); for(Int i=0;i<n;i++) cin>>x[i]; Int s=1<<n; vector<Int> dp(s,-1),sum(s,0); for(Int b=0;b<s;b++) for(Int i=0;i<n;i++) if((b>>i)&1) sum[b]+=x[i]; function<Int(Int)> dfs= [&](Int b){ Int &res=dp[b]; if(~res) return res; if(sum[b]<=t) return res=1; res=n+1; for(Int i=b;i;i=(i-1)&b){ if(i==b) continue; chmin(res,dfs(i)+dfs(b^i)); } return res; }; cout<<dfs(s-1)<<endl; return 0; }