結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2021-08-27 03:11:58 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 701 bytes |
コンパイル時間 | 3,518 ms |
コンパイル使用メモリ | 141,940 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-19 03:17:10 |
合計ジャッジ時間 | 4,600 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <cassert>#include <cmath>#include <algorithm>#include <iostream>#include <iomanip>#include <limits.h>#include <map>#include <queue>#include <set>#include <string.h>#include <vector>using namespace std;typedef long long ll;int main() {int C;cin >> C;int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; ++i) {cin >> A[i];}vector<int> dp(C + 1, C + 1);dp[0] = 0;for (int c = 0; c < C; ++c) {for (int i = 0; i < N; ++i) {int a = A[i];if (a + c > C) continue;dp[a + c] = min(dp[a + c], dp[c] + 1);}}if (dp[C] == C + 1) {cout << -1 << endl;} else {cout << dp[C] << endl;}return 0;}