编程介的小学生 2019-08-04 21:56 采纳率: 20.5%
浏览 145

物体配重的一个计算的问题的求解,用到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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)