标签:vector describe 2-2 temp class question ret 定义 color
1 class Solution { 2 public: 3 int cutRope(int number) { 4 if (number <= 1)return 0; 5 if (number < 5)return (number / 2)*(number - number / 2);//因为至少要分为2段 6 vector<int>dp(number + 1, 0); 7 dp[0] = 0, dp[1] = 1, dp[2] = 2, dp[3] = 3; 8 int maxN = 0; 9 for (int i = 4; i <= number; ++i) 10 { 11 maxN = 0; 12 for (int j = 1; j <= i / 2; ++j) 13 { 14 int temp = dp[j] * dp[i - j]; 15 maxN = maxN > temp ? maxN : temp; 16 dp[i] = maxN; 17 } 18 } 19 return dp[number]; 20 } 21 };
1 class Solution { 2 public: 3 int cutRope(int number) { 4 if (number <= 1)return 0; 5 if (number < 5)return (number / 2)*(number - number / 2);//因为至少要分为2段 6 int n3 = number / 3;//3的个数 7 if (number % 3 == 1)//最后剪的一段为4时,不要剪成3-1,要剪成2-2 8 n3--; 9 int n2 = (number - 3 * n3) / 2;//2的个数 10 return pow(3, n3)*pow(2, n2); 11 } 12 };
标签:vector describe 2-2 temp class question ret 定义 color
原文地址:https://www.cnblogs.com/zzw1024/p/11656418.html