A. Cut RIBBON

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Polycarpus has a ribbon, its length isN. He wants to cut the ribbon in a way that fulfils the following two conditions:

    • After the cutting each ribbon piece shoshould have LengthA,BOrC.
    • After the cutting the number of ribbon pieces shocould be maximum.

Help polycarpus and find the number of ribbon pieces after the required cutting.

Input

The first line contains four space-separated Integers N , A , B And C (1 digit ≤ DigitN, Bytes,A, Bytes,B, Bytes,CLimit ≤00004000) -
The length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers A , B And C 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.

Sample test (s) 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 2, the second piece has length 3.

In the second example polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.

Problem solving Description: although this question is DP, you can use the exhaustive method. The two duplicates are used to determine the number of occurrences of A and B, and then determine whether C meets the conditions.

 
# Include <iostream> # include <cstdio> # include <cstdlib> # include <cmath> # include <cstring> # include <string> # include <set> # include <algorithm> using namespace STD; int main () {int N, A, B, C; int I, j, T, max = 0; scanf ("% d ", & N, & A, & B, & C); for (I = 0; I * A <= N; I ++) {for (j = 0; I * A + J * B <= N; j ++) {If (n-I * A-J * B) % C = 0 & (n-I * A-J * B)/C + I + j> MAX) {max = (n-I * A-J * B)/C + I + J ;}} printf ("% d \ n", max); return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.