Cut ribbontime limit:2000msmemory limit:262144kbthis problem'll be judged onCodeforces. Original id:189a
64-bit integer IO format: %i64d Java class name: (any)
Polycarpus has a ribbon, it's length is n. He wants to cut the ribbon in a-a-fulfils, the following, and the conditions:
- After the cutting each ribbon piece should has length a, b or C.
- After the cutting, the number of the Ribbon pieces should be maximum.
Help Polycarpus and find the number of the ribbon pieces after the required cutting.
Input
The first line contains four space-separated integers n, a, b and C (1≤ n, a, b, C ≤4000)-the length of the original ribbon and the Acceptab Le 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, at least one correct ribbon cutting exists.
Sample InputInput
5 5 3 2
Output
2
Input
7 5 5 2
Output
2
SourceCodeforces Round #119 (Div. 2) Problem solving: DP under random
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =8010;4 intdp[maxn],n,piece[3];5 intMain () {6scanf"%d %d%d%d", &n,piece,piece+1, piece+2);7Memset (DP,0,sizeofDP);8 for(inti =0; I <= N; ++i) {9 for(intj =0; J <3; ++j)TenDP[I+PIECE[J]] = max (Dp[i+piece[j]], (dp[i]| | i = =0)? Dp[i] +1:0); One } Aprintf"%d\n", Dp[n]); - return 0; -}
View Code
Codeforces 189A Cut Ribbon