結果

問題 No.247 線形計画問題もどき
ユーザー finefine
提出日時 2016-04-04 23:24:17
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 689 bytes
コンパイル時間 1,331 ms
コンパイル使用メモリ 163,092 KB
実行使用メモリ 43,008 KB
最終ジャッジ日時 2024-04-14 21:37:38
合計ジャッジ時間 3,697 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 59 ms
43,008 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 13 ms
12,416 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 RE -
testcase_20 AC 35 ms
35,584 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 36 ms
36,352 KB
testcase_25 AC 27 ms
27,264 KB
testcase_26 RE -
testcase_27 AC 10 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int INF = 1000000;
    int c, n, a[100];
    cin >> c >> n;
    vector< vector<int> > dp(n + 1, vector<int>(c + 1, INF));
    for(int i = 0; i < n; i++){
        cin >> a[i];
        dp[i][0] = 0;
    }
    dp[n][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < a[i - 1]; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        for(int j = a[i - 1]; j <= c; j++) {
            dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i - 1]] + 1);
        }
    }
    if (dp[n][c] == INF) cout << -1 << "\n";
    else cout << dp[n][c] << "\n";
    return 0;
}
0