結果

問題 No.914 Omiyage
ユーザー 👑 jupirojupiro
提出日時 2019-10-26 00:21:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,465 bytes
コンパイル時間 1,043 ms
コンパイル使用メモリ 95,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:16:31
合計ジャッジ時間 1,581 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0