結果

問題 No.247 線形計画問題もどき
ユーザー fine
提出日時 2016-04-04 23:24:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 689 bytes
コンパイル時間 1,224 ms
コンパイル使用メモリ 163,796 KB
実行使用メモリ 43,008 KB
最終ジャッジ日時 2024-10-04 01:08:58
合計ジャッジ時間 3,525 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 17 RE * 6
権限があれば一括ダウンロードができます

ソースコード

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