結果

問題 No.247 線形計画問題もどき
ユーザー airisairis
提出日時 2015-07-20 22:28:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 75,288 KB
実行使用メモリ 44,668 KB
最終ジャッジ日時 2023-09-21 17:29:06
合計ジャッジ時間 2,336 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
44,368 KB
testcase_01 AC 13 ms
44,368 KB
testcase_02 AC 40 ms
44,552 KB
testcase_03 AC 14 ms
44,440 KB
testcase_04 AC 14 ms
44,420 KB
testcase_05 AC 13 ms
44,668 KB
testcase_06 AC 13 ms
44,360 KB
testcase_07 AC 13 ms
44,488 KB
testcase_08 AC 14 ms
44,416 KB
testcase_09 AC 14 ms
44,356 KB
testcase_10 AC 14 ms
44,484 KB
testcase_11 AC 14 ms
44,416 KB
testcase_12 AC 13 ms
44,360 KB
testcase_13 AC 13 ms
44,432 KB
testcase_14 AC 14 ms
44,376 KB
testcase_15 AC 13 ms
44,376 KB
testcase_16 AC 14 ms
44,420 KB
testcase_17 AC 15 ms
44,372 KB
testcase_18 AC 14 ms
44,368 KB
testcase_19 AC 19 ms
44,424 KB
testcase_20 AC 22 ms
44,404 KB
testcase_21 AC 15 ms
44,664 KB
testcase_22 AC 14 ms
44,376 KB
testcase_23 AC 15 ms
44,372 KB
testcase_24 AC 21 ms
44,368 KB
testcase_25 AC 20 ms
44,556 KB
testcase_26 AC 14 ms
44,380 KB
testcase_27 AC 15 ms
44,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}


0