結果
| 問題 |
No.247 線形計画問題もどき
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-17 22:51:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 748 bytes |
| コンパイル時間 | 1,293 ms |
| コンパイル使用メモリ | 157,808 KB |
| 実行使用メモリ | 42,788 KB |
| 最終ジャッジ日時 | 2024-07-07 11:03:15 |
| 合計ジャッジ時間 | 2,596 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
#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;
}