結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2016-04-06 20:56:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 597 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 59,956 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 11:14:25 |
合計ジャッジ時間 | 1,084 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>using namespace std;#define RREP(i,s,e) for (i = s; i >= e; i--)#define rrep(i,n) RREP(i,n,0)#define REP(i,s,e) for (i = s; i < e; i++)#define rep(i,n) REP(i,0,n)#define INF 100000000typedef long long ll;int a[100001];int dp[100001];int main() {int i, j, c, n;cin >> c >> n;fill(dp+1,dp+c+1,INF);rep (i,n) {int a;cin >> a;REP (j,a,c+1) dp[j] = min(dp[j-a]+1,dp[j]);}if (dp[c] != INF)cout << dp[c] << endl;elsecout << -1 << endl;return 0;}