結果
問題 |
No.733 分身並列コーディング
|
ユーザー |
![]() |
提出日時 | 2017-03-17 16:05:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,072 bytes |
コンパイル時間 | 825 ms |
コンパイル使用メモリ | 72,428 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-15 17:49:25 |
合計ジャッジ時間 | 3,735 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 45 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int C,N; cin>>C>>N; vector<int> W(N); for(auto &w:W)cin>>w; int DP[(1<<N)-1]; DP[0]=0; for(int b=1;b<(1<<N);b++){ int w=0; for(int k=0;(1<<k)<=b;k++){ if(b&(1<<k))w+=W[k]; } if(w<=C){ DP[b]=1; }else{ DP[b]=16; } } for(int k=1;k<=N;k++){ //nCkを列挙 int comb = (1<<k) -1; while(comb<1<<N){ for(int b=0;b<(1<<(N-k));b++){ int B=comb,j=0; for(int i=0;i<(N-k);i++){ while(B&(1<<j)) j++; if(b&(1<<i))B|=(1<<j); j++; } DP[B]=min(DP[B],DP[comb]+DP[B^comb]); } int x=comb&-comb, y=comb+x; comb = ((comb&~y)/x>>1)|y; } } //for(int i=0;i<(1<<N);i++) cout<<static_cast<std::bitset<3> >(i)<<' '<<DP[i]<<endl; cout<<DP[(1<<N)-1]<<endl; return 0; }