結果

問題 No.914 Omiyage
ユーザー ouoz1Vouoz1V
提出日時 2019-10-25 21:45:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 160,232 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:14:27
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using P=pair<int,int>;

const int MOD=1e9+7;
const int INF=1<<30;
const int MAX=1e5;

template<class T>
inline void xmin(T &a, T b){a=(a<b)?a:b;}
template<class T>
inline void xmax(T &a, T b){a=(a>b)?a:b;}

int n;
int m,k;
int a[11][11];
int dp[11][501];

void solve(){
    cin>>n>>m>>k;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        dp[1][a[0][i]]=1;
    }
    for(int i=1; i<n; i++){
        for(int j=0; j<m; j++){
            for(int ii=0; ii<501; ii++){
                if(ii+a[i][j]<=k && dp[i][ii]==1){
                    dp[i+1][ii+a[i][j]]=1;
                }
            }
        }
    }
    int cnt=0;
    int ans=0;
    while(cnt!=k+1){
        if(dp[n][cnt]){
            ans=cnt;
        }
        cnt++;
    }
    if(dp[n][ans]==0){
        cout<<-1<<endl;
        return;
    }
    cout<<k-ans<<endl;
}

signed main(){
    //while(1)
    solve();
}
0