結果
問題 | No.247 線形計画問題もどき |
ユーザー | vain0 |
提出日時 | 2015-07-17 23:29:19 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 722 ms |
コンパイル使用メモリ | 82,632 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 11:03:00 |
合計ジャッジ時間 | 1,717 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <cassert> #include <functional> #include <set> #include <ctime> #include <cmath> #include <climits> #include <cstring> #include <string> #include <queue> #include <map> #include <vector> #include <algorithm> #include <iostream> #include <cstdio> #ifndef ONLINE_JUDGE //POJ # include <complex> # include <random> # include <array> # define mkt make_tuple # define empb emplace_back #endif #ifdef _LOCAL # include "for_local.h" #else # define debug if (false) #endif using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I)) #define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I)) #define mkp make_pair #define all(_X) (_X).begin(), (_X).end() vector<int> as; int c; int n; static int const C_MAX = 100003, N_MAX = 100; array<int, C_MAX> dp; int const INF = 1<<29; signed main() { fill(all(dp), INF); dp[0] = 0; cin >> c >> n; rep(i, n) { int a; cin >> a; as.push_back(a); } rep(ci, c) { rep(ni, n) { int const c2 = ci + as[ni]; if ( c2 > C_MAX ) continue; dp[c2] = min(dp[c2], dp[ci] + 1); } } if ( dp[c] == INF ) dp[c] = -1; cout << dp[c] << endl; return 0; }