結果

問題 No.247 線形計画問題もどき
ユーザー kimiyukikimiyuki
提出日時 2016-04-19 17:51:37
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 59,836 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 11:14:30
合計ジャッジ時間 1,122 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
template <class T> bool setmin(T & l, T const & r) { if (not (r < l)) return false; l = r; return true; }
using namespace std;
const int inf = 1e9+7;
int main() {
    int c, n; cin >> c >> n;
    vector<int> as(n); repeat (i,n) cin >> as[i];
    vector<int> dp(c+1, inf);
    dp[0] = 0;
    repeat_from (i,1,c+1) {
        for (int a : as) {
            if (0 <= i-a) {
                setmin(dp[i], dp[i-a] + 1);
            }
        }
    }
    cout << (dp[c] == inf ? -1 : dp[c]) << endl;
    return 0;
}
0