結果

問題 No.247 線形計画問題もどき
ユーザー machymachy
提出日時 2015-07-17 23:44:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 63,320 KB
実行使用メモリ 42,840 KB
最終ジャッジ日時 2023-09-21 17:26:35
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
21,796 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 59 ms
42,840 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 4 ms
5,240 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 17 ms
18,548 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 39 ms
33,032 KB
testcase_20 AC 46 ms
36,948 KB
testcase_21 AC 14 ms
26,844 KB
testcase_22 AC 18 ms
27,388 KB
testcase_23 AC 13 ms
24,316 KB
testcase_24 AC 45 ms
36,708 KB
testcase_25 AC 35 ms
30,732 KB
testcase_26 AC 8 ms
9,288 KB
testcase_27 AC 13 ms
14,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int dp[101][100001] = {1000*1000*1000};

int main(){
    int C, N;
    cin >> C >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= C; j++){
            dp[i][j] = 1000*1000*1000;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= C; j++){
            dp[i+1][j] = dp[i][j];
        }
        for(int j = 0; j < a[i]; j++){
            int cost = dp[i][j];
            for(int k = j; k <= C; k += a[i]){
                dp[i+1][k] = min(dp[i+1][k], cost);
                cost = min(1000*1000*1000, dp[i+1][k] + 1);
                //cerr << i << " : " << k << " : " << dp[i+1][k] << endl;
            }
        }
    }
    if(dp[N][C] == 1000*1000*1000){
        cout << -1 << endl;
    }else{
        cout << dp[N][C] << endl;
    }
    return 0;
}
0