結果

問題 No.247 線形計画問題もどき
ユーザー koba-e964koba-e964
提出日時 2015-07-21 22:07:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 52,108 KB
実行使用メモリ 42,896 KB
最終ジャッジ日時 2023-09-21 17:30:26
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
29,944 KB
testcase_01 AC 3 ms
4,496 KB
testcase_02 AC 38 ms
42,840 KB
testcase_03 AC 3 ms
4,956 KB
testcase_04 AC 4 ms
5,280 KB
testcase_05 AC 4 ms
4,916 KB
testcase_06 AC 2 ms
4,416 KB
testcase_07 AC 3 ms
5,336 KB
testcase_08 AC 3 ms
4,392 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 5 ms
7,412 KB
testcase_12 AC 5 ms
7,416 KB
testcase_13 AC 3 ms
4,500 KB
testcase_14 AC 6 ms
9,464 KB
testcase_15 AC 4 ms
5,280 KB
testcase_16 AC 3 ms
4,560 KB
testcase_17 AC 15 ms
27,964 KB
testcase_18 AC 6 ms
9,460 KB
testcase_19 AC 22 ms
42,896 KB
testcase_20 AC 22 ms
42,832 KB
testcase_21 AC 23 ms
42,780 KB
testcase_22 AC 22 ms
42,864 KB
testcase_23 AC 20 ms
38,204 KB
testcase_24 AC 20 ms
38,136 KB
testcase_25 AC 21 ms
40,244 KB
testcase_26 AC 7 ms
13,608 KB
testcase_27 AC 12 ms
21,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;


const int N = 101, W = 100010;
const int inf = 2e7;

int dp[N][W];
int a[N];

int main(void){
  int c, n;
  cin >> c >> n;
  REP(i, 0, n) {
    cin >> a[i];
  }
  dp[0][0] = 0;
  REP(j, 1, W) {
    dp[0][j] = inf;
  }
  REP(i, 1, n + 1) {
    REP(j, 0, W) {
      if (j < a[i - 1]) {
	dp[i][j] = dp[i - 1][j];
      } else {
	dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i - 1]] + 1);
      }
    }
  }
  int res = dp[n][c];
  cout << (res == inf ? -1 : res) << endl;
}
0