結果
| 問題 | No.247 線形計画問題もどき |
| コンテスト | |
| ユーザー |
🍡yurahuna
|
| 提出日時 | 2016-02-26 20:29:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,421 bytes |
| 記録 | |
| コンパイル時間 | 611 ms |
| コンパイル使用メモリ | 74,904 KB |
| 実行使用メモリ | 49,064 KB |
| 最終ジャッジ日時 | 2024-09-22 14:01:52 |
| 合計ジャッジ時間 | 4,239 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 5 |
| other | AC * 2 TLE * 1 -- * 20 |
ソースコード
#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 EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#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];
// dp[i][j] = i番目までの和がjとなるようなsum(x)(i=0..i)の最小値(存在しなければ-1)
int dp[MAX_N][MAX_C + 1];
void input() {
cin >> C >> N;
REP(i, N) cin >> a[i];
}
void solve() {
REP(i, N) REP(j, C + 1) dp[i][j] = INF;
// x0について
int t_sum = 0;
int x0 = 0;
while (t_sum <= C) {
dp[0][t_sum] = x0;
t_sum += a[0];
x0++;
}
// 配るDP
REP(i, N - 1) {
REP(j, C + 1) {
if (dp[i][j] != INF) {
int nxt_sum = j;
int nxt_x = 0;
while (nxt_sum <= C) {
dp[i + 1][nxt_sum] = min(dp[i + 1][nxt_sum], dp[i][j] + nxt_x);
nxt_sum += a[i + 1];
nxt_x++;
}
}
}
}
if (dp[N - 1][C] != INF) {
cout << dp[N - 1][C] << endl;
} else {
cout << -1 << endl;
}
}
int main() {
input();
solve();
}
🍡yurahuna