結果

問題 No.247 線形計画問題もどき
ユーザー どららどらら
提出日時 2015-07-18 00:06:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,116 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 44,684 KB
最終ジャッジ日時 2023-09-22 18:35:29
合計ジャッジ時間 2,388 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 17 ms
44,516 KB
testcase_02 AC 42 ms
44,424 KB
testcase_03 AC 17 ms
44,320 KB
testcase_04 AC 17 ms
44,372 KB
testcase_05 AC 17 ms
44,356 KB
testcase_06 AC 17 ms
44,488 KB
testcase_07 AC 18 ms
44,520 KB
testcase_08 AC 16 ms
44,428 KB
testcase_09 AC 17 ms
44,316 KB
testcase_10 AC 17 ms
44,372 KB
testcase_11 AC 18 ms
44,320 KB
testcase_12 AC 18 ms
44,608 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 17 ms
44,320 KB
testcase_17 AC 27 ms
44,320 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 33 ms
44,384 KB
testcase_22 WA -
testcase_23 AC 32 ms
44,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 24 ms
44,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#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)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int dp[105][100005];

int main(){
  int C, N, aa;
  vector<int> a;
  cin >> C;
  cin >> N;
  rep(i,N){
    cin >> aa;
    a.push_back(aa);
  }

  rep(i,105){
    rep(j,100005){
      dp[i][j] = 100000000;
    }
  }
  
  int cnt = 1;
  int now = a[0];
  while(now < 100005){
    dp[0][now] = cnt;
    now += a[0];
    cnt++;
  }
  rep(i,N-1){
    rep(j,100005){
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
      if(j>=a[i+1]){
        dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-a[i+1]]+1);
      }
    }
  }


  if(dp[N-1][C]==100000000){
    cout << -1 << endl;
  }else{
    cout << dp[N-1][C] << endl;
  }
  
  return 0;
}
0