結果
| 問題 | No.247 線形計画問題もどき |
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-07-18 01:10:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 619 bytes |
| 記録 | |
| コンパイル時間 | 832 ms |
| コンパイル使用メモリ | 78,284 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-07 11:04:16 |
| 合計ジャッジ時間 | 1,688 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
int main(){
long long c;
cin >> c;
int n;
cin >> n;
vector<long long> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
sort(a.begin(), a.end());
vector<long long> dp(c+1, 1LL<<50);
dp[0] = 0;
for(int i=0; i<n; i++){
for(int j=0; j<=c; j++){
dp[j] = min( dp[j] , j-a[i]>=0 ? dp[j-a[i]] + 1 : 1LL<<50);
}
}
if(dp[c] == 1LL<<50){
cout << -1 << endl;
}else{
cout << dp[c] << endl;
}
return 0;
}
koyumeishi