結果
| 問題 |
No.914 Omiyage
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-27 01:58:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 669 bytes |
| コンパイル時間 | 3,310 ms |
| コンパイル使用メモリ | 208,636 KB |
| 最終ジャッジ日時 | 2025-01-21 18:42:44 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int a[10][10];
bool dp[11][501];
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin >> a[i][j];
}
}
memset(dp,false,sizeof(dp));
dp[0][0] = true;
for(int i=0;i<n;i++)
{
for(int j=k;j>=0;j--)
{
if(dp[i][j]==false)
{
continue;
}
for(int l=0;l<m;l++)
{
if(j + a[i][l] <= k)
{
dp[i+1][j + a[i][l]] = true;
}
}
}
}
for(int j=k;j>=0;j--)
{
if(dp[n][j])
{
cout << k -j << '\n';
return 0;
}
}
cout << -1 << '\n';
return 0;
}