結果
| 問題 |
No.914 Omiyage
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-25 21:23:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 652 ms |
| コンパイル使用メモリ | 76,568 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-24 16:20:05 |
| 合計ジャッジ時間 | 1,359 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int n, m, k;
cin >> n >> m >> k;
int a[n][m];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
}
}
vector<vector<bool>> dp(n+1, vector<bool>(k+1, 0));
dp[0][0] = true;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
for(int x = k-a[i][j]; x >= 0; x--){
dp[i+1][x+a[i][j]] = dp[i+1][x+a[i][j]]|dp[i][x];
}
}
}
for(int x = k; x >= 0; x--){
if(dp[n][x]){
cout << k-x << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}