# Codeforces 189A. Cut Ribbon

Source: Internet
Author: User

Test instructions

Give you a cloth of length N, and give you three lengths a, B, C. You can use scissors to cut the cloth, but after each cut, the length of the cloth must be a or B or C, ask according to this rule, you can cut the cloth into a few paragraphs.

Ideas:

The above question can be said, here is a wireless length of a, B, c of the cloth, so that you choose the most number, so that it is connected to the length of exactly N. This is obviously the root of the complete backpack expansion problem. So it's good to just apply a template.

Dp[i] = max (Dp[i], dp[I-v[j]] + w[j]).

Code:

`1#include <iostream>2#include <algorithm>3 4 using namespacestd;5typedefLong LongLL;6 Const intMAXN =4000;7 intDP[MAXN +3] = {0};8 9 intMain () {TenIos_base::sync_with_stdio (0); Cin.tie (0); One     intN, abc[4]; CIN >> N >> abc[0] >> abc[1] >> abc[2]; A      for(inti =1; I <= N; i++) Dp[i] =-100000000; //dp[0] initialized to 0, others initialized to negative infinity  -      for(inti =0; I <3; i++) for(intj = Abc[i]; J <= N; J + +) Dp[j] = max (Dp[j], Dp[j-abc[i]] +1); -cout << Dp[n] <<Endl; the     return 0; -}`

Codeforces 189A. Cut Ribbon

Related Keywords:

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.