結果
| 問題 | 
                            No.247 線形計画問題もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             syoken_desuka
                         | 
                    
| 提出日時 | 2015-07-18 01:23:29 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 1,263 bytes | 
| コンパイル時間 | 689 ms | 
| コンパイル使用メモリ | 86,920 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-07 11:04:33 | 
| 合計ジャッジ時間 | 1,393 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 23 | 
ソースコード
#include <algorithm>
#include <array>
#include <sstream>
#include <cstdio>
#include <functional>
#include <cstdlib>
#include <cctype>
#include <ostream>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
#define MOD 1000000007
//すいません
//メモリの確保ができてませんでした・・・
int main()
{  
    int c,n;
    int a[100];
    ll dp[100001];
    cin >> c >> n; 
    fill(a,a+100,-1);//invalid error on sort
    rep(i,n)
    {
        cin >> a[i];
    }
    rep(j,100001)
    {
        dp[j] = 1000000;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < c+1; j++)
        {
            if (j < a[i])
            {
                dp[j]= dp[j];
            } else
            {
                dp[j] = min(dp[j], dp[max(0,j-a[i])] + 1 );
            }
        }
    }
    if (dp[c] != 1000000)
    {
        cout << dp[c] << endl;
        return 0;
    }
    cout << "-1" << endl;
    return 0;
}
            
            
            
        
            
syoken_desuka