結果
| 問題 |
No.247 線形計画問題もどき
|
| コンテスト | |
| ユーザー |
🍡yurahuna
|
| 提出日時 | 2016-02-27 14:50:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 1,021 bytes |
| コンパイル時間 | 609 ms |
| コンパイル使用メモリ | 74,012 KB |
| 実行使用メモリ | 42,784 KB |
| 最終ジャッジ日時 | 2024-07-07 11:17:14 |
| 合計ジャッジ時間 | 1,408 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <string>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> P;
//typedef complex<double> C;
const int INF = 99999999;
const int MAX_N = 100;
const int MAX_C = 100000;
int C, N;
int a[MAX_N];
int dp[MAX_N + 1][MAX_C + 1];
void input() {
cin >> C >> N;
REP(i, N) cin >> a[i];
}
void solve() {
REP(i, N + 1) REP(j, C + 1) dp[i][j] = INF;
dp[0][0] = 0;
REP(i, N) {
REP(j, C + 1) {
if (j < a[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + 1);
}
}
}
if (dp[N][C] == INF) dp[N][C] = -1;
cout << dp[N][C] << endl;
}
int main() {
input();
solve();
}
🍡yurahuna