编程介的小学生 2019-05-12 21:03 采纳率: 20.5%
浏览 175

根据重量计算实现平衡统筹的一个算法,怎么运用C语言的程序编写代码的技术去实现的呢?

Problem Description
You are given a set of weight values and asked to measure something with a certain weight. Weight x is measurable with a set y of weight values if and only if you can do the following: Place one weight with value x on either the left or right side of the scale. Then place some combination of weights on the scale with values from the set y so that the left and right sides have the same total value. You may use each value in y zero or more times to achieve this. In order to reach the target, you choose a kind of weight randomly and try to measure with it. If you find it impossible, you choose an additional kind and try again until you can measure with the set of weights you have chosen. Now, please tell me the expect kinds of weight you have to choose.

Input
For each case, the first line is two integers n and m (1<=n<=15), which n represents the number of weights you have and m is the weight you have to measure. Followed by n positive integers ai (1<=i<=n), indicating the mass of each kind of weight. 0 < m,ai < 2^31.

Output
For each case, output -1 if you can't measure with all kinds of weight you have or the expect number of kinds you have to choose which rounded to 3 decimal places.

Sample Input
1 2
3
3 3
1 2 3
3 5
2 3 4

Sample Output
-1
1.333
2.333

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮