結果
| 問題 |
No.733 分身並列コーディング
|
| コンテスト | |
| ユーザー |
conf
|
| 提出日時 | 2017-03-17 16:34:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,048 bytes |
| コンパイル時間 | 694 ms |
| コンパイル使用メモリ | 73,636 KB |
| 実行使用メモリ | 10,528 KB |
| 最終ジャッジ日時 | 2024-10-15 17:49:29 |
| 合計ジャッジ時間 | 3,679 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / 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,co=0,bb=b;
for(int bb=b;bb;bb>>=1){
if(bb&1)co|=~B&-~B;
B|=~B&-~B;
}
DP[comb|co]=min(DP[comb|co],DP[comb]+DP[co]);
}
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<6> >(i)<<' '<<DP[i]<<endl;
cout<<DP[(1<<N)-1]<<endl;
return 0;
}
conf