Codeforces 189A Cut Ribbon

Source: Internet
Author: User

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

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.