zoukankan      html  css  js  c++  java
  • Preliminaries for Benelux Algorithm Programming Contest 2019:K. Knapsack Packing

    set和multiset的训练多多地去训练去训练

    One of the most difficult things about going on a holiday is making sure your luggage does not exceed the maximum weight. You, chairman of the Backpacker’s Association for Packing Carry-ons, are faced with exactly this problem.You are going on a lovely holiday with one of your friends, but now most of your time is spent in frustration while trying to pack your backpack. In order to optimize this process, you and your friend have independently set upon trying to find better ways to pack. 

    blackboard.jpg

    After some time you have a serious breakthrough! Somehow you managed to solve the Knapsack problem in polynomial time, defying expectations everywhere. You are not interested in any theoretical applications, so you immediately return to your friend’s apartment in order to now quickly pack your backpack optimally. 

    When you arrive there, you find that your friend has set upon her own solution, namely to enumerate all possible packings. This means that all items you possibly wanted to bring are scattered across the entire apartment, and it would take a really long time to get all the items back together. 

    Luckily you can use the work your friend has done. For every possible subset of items that you can possibly bring, she has written down the total weight of these items. Alas, she did not write down what items were part of this total, so you do not know what items contributed to each total weight. If the original weights of the items formed a collection (a1, . . . , an) of non-negative integers, then your friend has written down the multiset

    forma.jpg

    For example, if your friend had two items, and the weights of those two items are2, 3, then your friend has written down

     • 0, corresponding to the empty set {}; 

    • 2, corresponding to the subset {2}; 

    • 3, corresponding to the subset {3};

     • 5, corresponding to the subset {2, 3}. 

    You want to reconstruct the weights of all the individual items so you can start using your Knapsack algorithm. It might have happened that your friend made a mistake in adding all these weights, so it might happen that her list is not consistent.

    Input:

    • One line containing a single integer 1 ≤ n ≤ 18 the number of items.

     • 2^n lines each containing a single integer 0 ≤ w ≤ 2^28, the combined weight of a subset of the items. Every subset occurs exactly once.

    Output:

    output.jpg

    Sample Input 4Sample Output 4
    2
    0
    1
    1
    2
    1
    1

    样例输入1

    1
    0
    5

    样例输出1

    5

    样例输入2

    3
    7
    5
    2
    4
    1
    6
    3
    0

    样例输出2

    1
    2
    4

    样例输入3

    2
    0
    1
    2
    4

    样例输出3

    impossible
  • 相关阅读:
    PyCharm 激活方法
    Android Studio 如何启动自身模拟器来调试(一般人我不告诉他)
    Android 打造一款逼格高的圆形图片
    Android Observer观察模式基础入门
    Android OkHttp3(完美封装)Get异步获取数据、Post异步获取数据、Form表单提交、文件下载
    Kotlin学习资料
    Android 导入外部字体的完美解决方案
    Android 开发者福利Google Developers中国网站发布
    Android 自定义弹出框 EditText获取光标后键盘遮挡,及初始化弹出键盘问题解决
    Android ListView动态设置高度
  • 原文地址:https://www.cnblogs.com/dragondragon/p/12515918.html
Copyright © 2011-2022 走看看