結果
| 問題 |
No.914 Omiyage
|
| ユーザー |
|
| 提出日時 | 2019-10-26 00:21:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,465 bytes |
| コンパイル時間 | 926 ms |
| コンパイル使用メモリ | 95,016 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 16:29:17 |
| 合計ジャッジ時間 | 1,570 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MAX = 510000;
const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int n, m, k;
vector<vector<int>> dp;
int dfs(vector<vector<int>>& v, int depth, int sum) {
if (depth == n)
return sum;
//cout << depth << " " << sum << endl;
if (dp[depth][sum] != -1) return dp[depth][sum];
int max_v = 0;
for (int i = 0; i < m; i++) {
int tmp = sum + v[depth][i];
if (tmp > k)
continue;
int x = dfs(v, depth + 1, tmp);
max_v = max(max_v, x);
}
return dp[depth][sum] = max_v;
}
int main()
{
cin >> n >> m >> k;
vector<vector<int>> v(n, vector<int>());
dp = vector<vector<int>>(n, vector<int>(k + 1, -1));
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int x;
cin >> x;
if (j == 0)
ans += x;
v[i].push_back(x);
}
}
if (ans > k) {
cout << -1 << "\n";
return 0;
}
ans = dfs(v, 0, 0);
cout << k - ans << "\n";
return 0;
}