結果
| 問題 |
No.914 Omiyage
|
| コンテスト | |
| ユーザー |
Dente
|
| 提出日時 | 2019-10-25 21:53:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 882 bytes |
| コンパイル時間 | 1,353 ms |
| コンパイル使用メモリ | 166,772 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-24 16:27:38 |
| 合計ジャッジ時間 | 2,002 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int n,m,k;
int a[10][10];
int dp[11][501];
int DFS(int depth, int use){
if(dp[depth][use] != -1){
return dp[depth][use];
}
if(depth == n){
return k - use;
}
int res = INF;
REP(i,m){
if(use + a[depth][i] <= k){
res = min(res, DFS(depth + 1, use + a[depth][i]));
}
}
return dp[depth][use] = res;
}
signed main(){
cin >> n >> m >> k;
REP(i,n){
REP(j,m){
cin >> a[i][j];
}
}
memset(dp, -1, sizeof(dp));
DFS(0, 0);
if(dp[0][0] == INF){
cout << -1 << endl;
}else{
cout << dp[0][0] << endl;
}
return 0;
}
Dente