結果

問題 No.50 おもちゃ箱
ユーザー ayame_pyayame_py
提出日時 2016-01-20 16:24:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,040 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 162,608 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 13:32:39
合計ジャッジ時間 4,198 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 86 ms
4,348 KB
testcase_06 AC 10 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 28 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 12 ms
4,348 KB
testcase_28 WA -
testcase_29 AC 39 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 36 ms
4,348 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 11 ms
4,348 KB
testcase_39 WA -
testcase_40 AC 58 ms
4,348 KB
testcase_41 AC 50 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i < (ll)(m); i++)
#define INF 1000000007
#define pb push_back

typedef long long ll;

int N,M;
int A[11],B[11];
int dp[11][2000];

int dfs(int m,int rest){
    if(rest==0) return 0;
    if(m==M) return dp[m][rest]=INF+1;
    if(dp[m][rest]!=INF) return dp[m][rest];
    REP(mask,1<<N){
        int inbox = rest & mask;
        if(inbox==0) continue;
        int sum_toy=0;
        REP(i,N){
            if(inbox>>i & 1) sum_toy+=A[i];
        }
        if(sum_toy<=B[m]) dp[m][rest]=min(dp[m][rest],1+dfs(m+1,rest-inbox));
        
    }
    if(dp[m][rest]!=INF) return dp[m][rest];
    return dp[m][rest]=INF+1;
}

int main(){
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    sort(A,A+N,greater<int>());
    cin >> M;
    REP(i,M){
        cin >> B[i];
    }
    fill(dp[0],dp[11],INF);
    int ans = dfs(0,(1<<N)-1);
    if(ans<INF) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}
0