結果
| 問題 | 
                            No.247 線形計画問題もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             🍡yurahuna
                         | 
                    
| 提出日時 | 2016-02-26 21:34:49 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 992 bytes | 
| コンパイル時間 | 792 ms | 
| コンパイル使用メモリ | 73,972 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-07 11:13:58 | 
| 合計ジャッジ時間 | 1,268 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 23 | 
ソースコード
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <string>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> P;
//typedef complex<double> C;
const int INF = 99999999;
const int MAX_N = 100;
const int MAX_C = 100000;
int C, N;
int a[MAX_N];
int dp[MAX_C + 1];
void input() {
	cin >> C >> N;
	REP(i, N) cin >> a[i];
}
void solve() {
	REP(j, C + 1) dp[j] = INF;
	dp[0] = 0;
	REP(i, N) {
		REP(j, C + 1) {
			if (j + a[i] <= C) {
				dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1);
			}
		}
	}
	if (dp[C] >= INF) dp[C] = -1;
	cout << dp[C] << endl;
}
int main() {
	input();
	solve();
}
            
            
            
        
            
🍡yurahuna