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 ;}