本文共 2623 字,大约阅读时间需要 8 分钟。
time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output
Polycarpus has a ribbon, its length is . He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length , or .
- After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting.
Input
The first line contains four space-separated integers , , and — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers , and can coincide.
Output
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
Examples
input
5 5 3 2
output
2
input
7 5 5 2
output
2
Note
In the first example Polycarpus can cut the ribbon in such way: the first piece has length , the second piece has length .
In the second example Polycarpus can cut the ribbon in such way: the first piece has length , the second piece has length .
Solve
完全背包,看成给出三种商品,恰好能够装满背包的情况
注意初始化的问题,如果把 数组全部初始化为 的话,需要注意 的情况。或者就全部初始值给成小于 的数
Code
/************************************************************************* > Author: WZY > School: HPU > Created Time: 2019-04-01 18:30:38 ************************************************************************/#include#include #include #include #include #include #include #include #include #include
转载地址:https://www.cnblogs.com/Friends-A/p/11054959.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!