結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2017-05-25 19:30:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 577 bytes |
コンパイル時間 | 1,166 ms |
コンパイル使用メモリ | 159,388 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 12:04:48 |
合計ジャッジ時間 | 2,012 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include"bits/stdc++.h"//#include<bits/stdc++.h>using namespace std;#define print(x) cout<<x<<endl;#define rep(i,a,b) for(int i=a;i<b;i++)#define REP(i,a) for(int i=0;i<a;i++)typedef long long ll;typedef pair<int, int> PI;typedef pair<int, PI> V;const ll mod = 100000000;int c, n, a[102];int dp[100002] = {};int main() {REP(j, 100002)dp[j] = mod;cin >> c; cin >> n;REP(i, n)cin >> a[i];dp[0] = 0;REP(i, c+1) {REP(j, n) {if (i - a[j] < 0)continue;dp[i] = min(dp[i],dp[i - a[j]]+1);}}int ans = dp[c] == mod ? -1 : dp[c];print(ans);}