結果

問題 No.247 線形計画問題もどき
ユーザー machymachy
提出日時 2015-07-17 23:31:16
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 905 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 65,236 KB
実行使用メモリ 42,992 KB
最終ジャッジ日時 2023-09-22 18:21:07
合計ジャッジ時間 4,004 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 AC 54 ms
42,992 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
5,656 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 RE -
testcase_20 AC 45 ms
35,876 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 AC 12 ms
10,944 KB
権限があれば一括ダウンロードができます

ソースコード

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];
    }
    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++){
            dp[i+1][j] = dp[i][j];
        }
        for(int j = 0; j < a[i]; j++){
            if(dp[i][j] == 1000*1000*1000) continue;
            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 = 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