結果

問題 No.247 線形計画問題もどき
ユーザー machymachy
提出日時 2015-07-17 22:45:59
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 865 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 68,984 KB
実行使用メモリ 24,304 KB
最終ジャッジ日時 2023-09-22 17:56:36
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
24,304 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int C, N;
    cin >> C >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int i = 1; i < a.size(); i++){
        if(a[i] == a[i-1]){
            a.erase(a.begin()+i);
            i--;
        }
    }
    N = a.size();
    vector<vector<int> > dp(N+1, vector<int>(C+1, 1000*1000*1000));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= C; j++){
            int cost = 0;
            for(int k = j; k <= C; k += a[i]){
                dp[i+1][k] = min(dp[i+1][k], dp[i][j] + cost);
                cost++;
            }
        }
    }
    if(dp[N][C] == 1000*1000*1000){
        cout << -1 << endl;
    }else{
        cout << dp[N][C] << endl;
    }
    return 0;
}
0