結果

問題 No.733 分身並列コーディング
ユーザー face4
提出日時 2019-10-25 10:06:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 191 ms / 1,500 ms
コード長 667 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 69,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 06:30:21
合計ジャッジ時間 5,684 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

// 1.2e8なので危ない
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int T, n;
    cin >> T >> n;
    vector<int> t(n);
    for(int i = 0; i < n; i++)  cin >> t[i];
    vector<int> dp(1<<n, 0);
    for(int s = 1; s < 1<<n; s++){
        for(int i = 0; i < n; i++){
            if(s>>i&1)  dp[s] += t[i];
        }
        if(dp[s] <= T)   dp[s] = 1;
        else             dp[s] = 20;
    }
    dp[0] = 0;
    for(int s = 1; s < 1<<n; s++){
        int sub = s;
        do{
            dp[s] = min(dp[s], dp[s-sub]+dp[sub]);
            sub = (sub-1)&s;
        }while(sub != s);

    }
    cout << dp.back() << endl;
    return 0;
}
0