結果

問題 No.247 線形計画問題もどき
ユーザー pekempeypekempey
提出日時 2015-07-17 22:51:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 144,252 KB
実行使用メモリ 43,080 KB
最終ジャッジ日時 2023-09-21 17:24:46
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
41,612 KB
testcase_01 AC 6 ms
40,252 KB
testcase_02 AC 48 ms
42,796 KB
testcase_03 AC 6 ms
40,424 KB
testcase_04 AC 7 ms
40,236 KB
testcase_05 AC 6 ms
40,432 KB
testcase_06 AC 7 ms
40,260 KB
testcase_07 AC 18 ms
42,888 KB
testcase_08 AC 17 ms
43,080 KB
testcase_09 AC 7 ms
40,296 KB
testcase_10 AC 17 ms
42,792 KB
testcase_11 AC 7 ms
40,228 KB
testcase_12 AC 7 ms
40,372 KB
testcase_13 AC 7 ms
40,236 KB
testcase_14 AC 7 ms
40,224 KB
testcase_15 AC 7 ms
40,300 KB
testcase_16 AC 7 ms
40,300 KB
testcase_17 AC 14 ms
41,256 KB
testcase_18 AC 8 ms
40,528 KB
testcase_19 AC 25 ms
41,924 KB
testcase_20 AC 29 ms
42,420 KB
testcase_21 AC 9 ms
40,480 KB
testcase_22 AC 11 ms
40,744 KB
testcase_23 AC 10 ms
40,552 KB
testcase_24 AC 33 ms
42,892 KB
testcase_25 AC 24 ms
41,912 KB
testcase_26 AC 14 ms
41,568 KB
testcase_27 AC 14 ms
41,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int C, N;
int dp[101][100001];
int a[100];

int solve() {
    rep (i, 101) rep (j, C + 1) dp[i][j] = inf;
    dp[0][0] = 0;

    rep (i, N) {
        rep (j, C + 1) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (j + a[i] <= C) {
                dp[i + 1][j + a[i]] = min(dp[i + 1][j + a[i]], dp[i + 1][j] + 1);
            }
        }
    }

    return dp[N][C];
}

int main() {
    cin >> C >> N;
    rep (i, N) cin >> a[i];
    int ans = solve();
    if (ans == inf) ans = -1;
    cout << ans << endl;
}
0