結果
問題 | No.247 線形計画問題もどき |
ユーザー |
|
提出日時 | 2015-07-21 22:07:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 591 bytes |
コンパイル時間 | 465 ms |
コンパイル使用メモリ | 56,116 KB |
実行使用メモリ | 42,772 KB |
最終ジャッジ日時 | 2024-07-07 11:08:28 |
合計ジャッジ時間 | 1,756 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <iostream> #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; const int N = 101, W = 100010; const int inf = 2e7; int dp[N][W]; int a[N]; int main(void){ int c, n; cin >> c >> n; REP(i, 0, n) { cin >> a[i]; } dp[0][0] = 0; REP(j, 1, W) { dp[0][j] = inf; } REP(i, 1, n + 1) { REP(j, 0, W) { if (j < a[i - 1]) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i - 1]] + 1); } } } int res = dp[n][c]; cout << (res == inf ? -1 : res) << endl; }