結果
| 問題 |
No.247 線形計画問題もどき
|
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2015-07-18 23:39:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 2,000 ms |
| コード長 | 973 bytes |
| コンパイル時間 | 565 ms |
| コンパイル使用メモリ | 78,164 KB |
| 実行使用メモリ | 43,008 KB |
| 最終ジャッジ日時 | 2024-07-07 11:09:51 |
| 合計ジャッジ時間 | 1,505 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <string> VS;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, LL> PIL;
typedef vector <PIL> VPIL;
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define sort(c) sort((c).begin(),(c).end())
#define range(i,a,b) for(int i=(a); i < (b); i++)
#define rep(i,n) range(i,0,n)
#define MAX_INT 2147483647
int main(){
int C, N, UB = 100001;
VI a;
VVI dp;
cin >> C >> N;
a.resize(N);
rep(i,N) cin >> a[i];
dp = VVI(N+1, VI(C+1, UB));
rep(i,N){
dp[i][0] = 0;
range(j,a[i],C+1) dp[i][j] = min(dp[i][j], dp[i][j-a[i]]+1);
rep(j,C+1) dp[i+1][j] = dp[i][j];
}
cout << ((dp[N][C] != UB)? dp[N][C] : -1) << endl;
return 0;
}
Tawara