結果

問題 No.247 線形計画問題もどき
ユーザー syoken_desukasyoken_desuka
提出日時 2015-07-17 23:10:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,540 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 92,964 KB
実行使用メモリ 14,544 KB
最終ジャッジ日時 2023-09-22 18:08:59
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 3 ms
7,304 KB
testcase_03 AC 3 ms
7,280 KB
testcase_04 AC 4 ms
7,348 KB
testcase_05 AC 3 ms
7,300 KB
testcase_06 AC 3 ms
7,284 KB
testcase_07 AC 3 ms
7,400 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <sstream>
#include <cstdio>
#include <functional>
#include <cstdlib>
#include <cctype>
#include <ostream>
#include<complex>
#include <cmath>
#include <iostream>
#include <stack>
#include <fstream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <string>
using namespace std;
#define OB (bitset<32>)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define ALLOF(c) begin(), (c),end()

typedef long long ll;

#define PI acos(-1)
#define EPS 0.000000001
#define MOD 1000000007



int main()
{  
    int dp[10001][101];
    int c;
    int n;
    int a[100];
    cin >>c >> n;
    fill(a,a+100,-1);//invalid error on sort
    fill(*dp,*dp +10001*101, MOD);//invalid num     mod? dekai
    rep(i,n)
    {
        cin >> a[i];
    }
    sort(a,a+100,greater<int>());
    dp[0][0] = 0;
    rep(i,n)
    {
        rep(j,c)
        {
            if (dp[i][j] != MOD)
            {
                for (int k = 0;; k++)
                {
                    if ((j + k*a[i]) > c)
                    {
                        break;
                    }
                    dp[i+1][j+k*a[i]] =  min(dp[i][j] + k,dp[i+1][j + k*a[i]]);
                }
            }
        }
        if (dp[i+1][c] != MOD)
        {
            cout << dp[i+1][c] <<endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

0