結果
問題 | No.15 カタログショッピング |
ユーザー |
![]() |
提出日時 | 2015-02-20 11:14:09 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 826 bytes |
コンパイル時間 | 60 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 63,808 KB |
最終ジャッジ日時 | 2024-06-23 21:22:57 |
合計ジャッジ時間 | 3,091 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 2 |
ソースコード
def dfs(index, money, goods, dic, end): global N, S, P if goods: dic.setdefault(money, []).append(list(goods)) if index == end: return goods.append(index + 1) dfs(index + 1, money + P[index], goods, dic, end) goods.pop() dfs(index + 1, money, goods, dic, end) N, S = map(int, raw_input().split()) P = [int(raw_input()) for i in xrange(N)] first = {0:[]} second = {0:[]} dfs(0, 0, [], first, N / 2) dfs(N / 2, 0, [], second, N) ans = [] for money, l in first.iteritems(): if not S - money in second: continue for first_goods in l: for second_goods in second[S - money]: goods = first_goods + second_goods if not goods in ans: ans.append(goods) ans.sort() for goods in ans: print ' '.join(map(str, goods))