結果

問題 No.914 Omiyage
ユーザー CleyLCleyL
提出日時 2020-01-29 02:03:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 70,976 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 21:03:03
合計ジャッジ時間 1,589 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > A(11,vector<int>(11));
int n,m,k;
int memo[11][501];
int DFS(int nw,int c){
  if(c > k){return -1;}
  if(memo[nw][c]){
    return memo[nw][c];
  }
  if(nw == n){
    return c;
  }
  int ans = -1;
  for(int i = 0; m > i; i++){
    ans = max(ans,DFS(nw+1,c+A[nw][i]));
  }
  memo[nw][c] = ans;
  return ans;
}

int main(){
  cin>>n>>m>>k;
  for(int i = 0; n > i; i++){
    for(int j = 0; m > j; j++){
      cin>>A[i][j];
    }
  }
  int z = DFS(0,0);
  cout << (z==-1?-1:k-z) << endl;
}
0