Title Link: Http://codeforces.com/problemset/problem/189/A
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