結果
問題 | No.247 線形計画問題もどき |
ユーザー |
|
提出日時 | 2015-10-11 00:39:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 725 bytes |
コンパイル時間 | 1,006 ms |
コンパイル使用メモリ | 159,208 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 11:11:36 |
合計ジャッジ時間 | 1,761 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)#define rep(i, a) REP(i, 0, a)#define EACH(i, a) for (auto i: a)#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)#define ALL(a) (a.begin()), (a.end())#define ISIN(a, x) (a.find(x) != a.end())int C, N;int a[105];int dp[100005];const int INF = 1000000000;int main(void) {// breath deeply and calm downcin >> C;cin >> N;rep(i, N) cin >> a[i];rep(i, C + 1) dp[i] = INF;dp[0] = 0;rep(i, C + 1)rep(j, N)if (i - a[j] >= 0)dp[i] = min(dp[i], dp[i - a[j]] + 1);cout << (dp[C] < INF ? dp[C]:-1) << endl;return 0;}