結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2015-07-20 22:28:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 678 ms |
コンパイル使用メモリ | 80,176 KB |
実行使用メモリ | 44,520 KB |
最終ジャッジ日時 | 2024-07-07 11:07:02 |
合計ジャッジ時間 | 2,521 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <iostream>#include <algorithm>#include <string>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <numeric>#include <bitset>#include <complex>#define rep(x, to) for (int x = 0; x < (to); x++)#define REP(x, a, to) for (int x = (a); x < (to); x++)#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)#define EPS (1e-14)#define INF (1e+9)using namespace std;typedef long long ll;typedef pair<int, int> PII;typedef pair<ll, ll> PLL;typedef complex<double> Complex;typedef vector< vector<int> > Mat;int C;int N;int a[100005];int dp[105][100005];int main() {rep(i, 105) rep(j, 100005) dp[i][j] = INF;cin >> C;cin >> N;rep(i, N) cin >> a[i];dp[0][0] = 0;for (int i = 0; i < N; i++) {for (int j = 0; j <= C; j++) {dp[i + 1][j] = dp[i][j];if (j - a[i] >= 0) {dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - a[i]] + 1);}}}if (dp[N][C] == INF) {cout << -1 << endl;} else {cout << dp[N][C] << endl;}return 0;}