結果
| 問題 |
No.247 線形計画問題もどき
|
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2019-03-07 19:03:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 632 bytes |
| コンパイル時間 | 1,440 ms |
| コンパイル使用メモリ | 170,556 KB |
| 実行使用メモリ | 83,268 KB |
| 最終ジャッジ日時 | 2024-07-07 12:35:44 |
| 合計ジャッジ時間 | 3,007 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
const int INF = 1LL << 60;
int dp[101][101010];
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int C,N; cin >> C >> N;
vector<int> a(N);
for(int i = 0; i < N; i++){
cin >> a[i];
}
fill(dp[0],dp[100]+101010,INF);
dp[0][0] = 0;
for(int i = 0; i < N; i++){
for(int j = 0; j <= C; j++){
if(j-a[i] >= 0){
dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+1);
}
else dp[i+1][j] = dp[i][j];
}
}
if(dp[N][C] == INF) cout << -1 << endl;
else cout << dp[N][C] << endl;
return 0;
}
oxyshower