当前位置:编程学习 > JAVA >>

求大神们看过来,帮小弟看看这个你们会吗?

这是小弟的一个作业,自觉好难,求大神相助,会写的请速速联系qq 908179820,加备注啊~有偿报酬哦详聊
中文都代大家翻译好了,当然要是你懂英文那更好~


编写一个程序以解决如下问题。给出一组硬币的面值,重量和一个数量(全都是正整数)。当为数量找零时,你必须最小化这些硬币的总重量,如果不可能找零,你应该说明这一点。
细节请查看案例的输入与输出。
Write a program to solve the following problem. You are given a list of possible coin denominations and weights,
and an amount (all of these are positive integers). You must minimize the total weight of coins while making
exact change for the amount. If exact change is not possible, you should report this fact.


案例输入文件为:2013A5_sample_input.txt.txt
1 5 10 20 501 4 11 13 5583 4 51 1 12


案例输出文件为:2013A5_sample_output.txt.txt
Problem number: 1
min weight: 7
Problem number: 2
not possible


原输出文档内容为:
Problem number: 1min weight: 7Problem number: 2not possible

上面是方便大家理解,编写时请按原文档输出格式来~




注意点:

当你读取输入时,请确保使用一个合适的文字编辑器,它不会插入虚假的空行。
When you read them, be sure to use a proper text editor that doesn't 
insert spurious blank lines.

你的程序不需要检查输入文件是否是正确的格式(当然它会是正确的格式)。
Your program doesn't need to check that the input file is correctly formatted 
(it will be). 

你可以假设最大的重量,面值和数量都小于二十亿,所以就不必担心溢出错误/溢位错误。
You can assume that the maximum weight, denomination and amount are all less 
than 2 billion, so as not to have to worry about overflow errors.




编程中汇集的问题:

推荐使用JAVA,但C与C++也可以使用
 Java is recommended, but C or C++ may also be used. 

你的答案必须在一个文件内,包含所有你使用的classes.你可以假设输入与输出都是标准的。输入的每一行代表了一个string。
 Your answer to question should be a single file (containing all nonstandard classes you use). You can
assume that input will come from standard input in a stream that represents one string per line. Output
should be sent to standard out. You may assume that the markers have access to all standard libraries.

案例的输入与输出是标准的格式。完成程序后的测试输入会按照案例的输入格式进行。确保你的输出格式如案例的输出格式一样。
注意每个空行和一些不标准的文字编辑软件如微软的Word。 要取得最佳结果,请使用Linux/Unix环境。
 A sample input and output file for each question will be available. The markers may check the output
with a text comparison program, so it must be in EXACTLY the right format. Pay attention to line
breaks and beware of nonstandard software such as anything made by Microsoft. For best results, use a
Linux/Unix environment.

你的程序会被随机生成的测试文件检查,有些会非常大。得分会基于正确率与程序的速度。但完全正确是得到满分的保证。
如果有任何结果错误,将得到零分无论是何种错误。
 Your program(s) may be tested on randomly generated input files, some of which may be very large. Marks
will be allocated for correctness and speed of the programs. Simply \passing" the largest input on the
automarker may not always guarantee maximum marks, but it will guarantee full marks for correctness.
If full marks for correctness are not obtained, then the marks for speed are automatically set to zero.

备注是不会算分的,但至少包含一些代码目的的注解。
 No marks will be awarded for comments, but you must at least include comments with the the purpose of the code.
Java 算法 --------------------编程问答-------------------- 说实在的,这题还是蛮有意思的。
目前临时想到的思维就是递归的方式,先把金额尽量小的细化,然后在匹配钱币的面值 --------------------编程问答-------------------- 顶顶顶,求大神啊 --------------------编程问答-------------------- 贪心法。
将每一个硬币的值与重量转化为一个比值。
找零时,从里需拿出小于零钱的比值最大的一枚。重原零钱中减去该枚硬币的面值得到新的零钱。
如此反复直到零钱为0 --------------------编程问答-------------------- 背包问题网上搜有很多方法,现成的代码也比较多
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,