結果

問題 No.733 分身並列コーディング
ユーザー confconf
提出日時 2017-03-17 16:05:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,072 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 72,324 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-05 20:46:38
合計ジャッジ時間 3,594 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0