結果

問題 No.50 おもちゃ箱
ユーザー ss_koishiss_koishi
提出日時 2014-11-07 16:07:32
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 811 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 60,000 KB
実行使用メモリ 7,532 KB
最終ジャッジ日時 2023-08-30 01:51:45
合計ジャッジ時間 3,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 180 ms
7,460 KB
testcase_06 AC 8 ms
5,372 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 6 ms
5,168 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 26 ms
7,420 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 6 ms
5,400 KB
testcase_22 AC 14 ms
7,436 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 63 ms
7,460 KB
testcase_29 AC 49 ms
7,412 KB
testcase_30 AC 27 ms
7,404 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 139 ms
7,460 KB
testcase_33 AC 152 ms
7,460 KB
testcase_34 AC 144 ms
7,452 KB
testcase_35 AC 76 ms
7,508 KB
testcase_36 AC 116 ms
7,472 KB
testcase_37 AC 58 ms
7,452 KB
testcase_38 AC 39 ms
7,532 KB
testcase_39 AC 105 ms
7,416 KB
testcase_40 AC 200 ms
7,456 KB
testcase_41 AC 107 ms
7,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define INF (2 << 28)
using namespace std;

int n, m;
int a[11], b[11], dp[1<<10][1<<10];

int rec(int toy, int used){

  //cout << toy << " " << used << endl;
  if(toy == 0) return __builtin_popcount(used);
  if(dp[toy][used]) return dp[toy][used];
  
  int ret = INF;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(a[i] <= b[j] && toy >> i & 1){
	b[j] -= a[i];
	ret = min(ret, rec(~(1 << i) & toy, used | (1 << j)));
	b[j] += a[i];
      }
    }
  }

  return dp[toy][used] = ret;
}
    
int main(){
  
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  cin >> m;
  for(int i = 0; i < m; i++) cin >> b[i];
  
  int d = rec((1<<n)-1, 0);
  if(d == INF) cout << -1 << endl;
  else cout << d << endl;
}
0