結果
| 問題 |
No.914 Omiyage
|
| コンテスト | |
| ユーザー |
ScottShelby
|
| 提出日時 | 2020-10-04 18:19:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 804 bytes |
| コンパイル時間 | 1,883 ms |
| コンパイル使用メモリ | 180,948 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-19 17:37:14 |
| 合計ジャッジ時間 | 2,840 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;
int n, m, K;
vector<vector<int>> a;
vector<vector<bool>> dp(11, vector<bool>(510));
int main() {
cin >> n >> m >> K;
a.resize(n, vector<int>(m));
rep(i, n) {
rep(j, m) {
cin >> a[i][j];
}
}
dp[0][0] = true;
rep(i, n) rep(j, m) rep(k, K) {
if (dp[i][k] == false) continue;
int ni = i + 1;
int nk = k + a[i][j];
if (nk > K) continue;
dp[ni][nk] = true;
}
int ans = INF;
for (int i = K; i >= 0; --i) {
if (dp[n][i]) {
cout << K - i << endl;
return 0;
}
}
cout << -1 << endl;
}
ScottShelby