Description Title
give you a string of length n, please cut the rope length of the integer m sections (m, n are integers, n> 1 and m> 1), the length of each rope is referred to as k [0] , k [1], ..., k [m]. Will k [0] xk [1] x ... xk [m] maximum possible product is how much? For example, when the length of the rope is 8:00, we cut it into lengths of three sections 2,3,3 of the product obtained at this time is the maximum 18.
Solution:
1, dynamic programming
2, a special case F (2) = 1, F (. 3) = 2
. 3, F (n-) = max (F (I) * F (Ni))
class Solution {
public:
int cutRope(int number) {
if(number==2 || number==3)
return number-1;
vector<int> f;
for(int i=0; i<4; i++)
f.push_back(i);
for(int i=4; i<=number; i++)
{
int maxn = 0;
for(int j=2; j<=i; j++)
{
if(f[j]*f[i-j] > maxn)
maxn = f[j]*f[i-j];
}
f.push_back(maxn);
}
return f[number];
}
};