
本文共 2457 字,大约阅读时间需要 8 分钟。
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������
���������������������������������������������������������������������������������������������������������������������������������������������n���������������������������������������������������������������������������������
������������������
������������������������������������������������������������������������������������������������������������
������������
���������������������������������������������������������������������������
������������
int MaxProductAfterCutting_Solution(int length) { int[] product = new int[length + 1]; product[0] = 0; product[1] = 1; product[2] = 2; product[3] = 3; int Max_Value = 0; for (int i = 4; i <= length; ++i) { Max_Value = 0; for (int j = 1; j <= i / 2; ++j) { int current = product[j] * product[i - j]; if (current > Max_Value) { Max_Value = current; } } product[i] = Max_Value; } return product[length];}
������������
int MaxProductAfterCutting_Solution(int length) { if (length <= 2) { return 0; } if (length == 3) { return 1; } int times_of_3 = length / 3; if ((length % 3) == 1) { times_of_3--; } int times_of_2 = (length - times_of_3 * 3) / 2; return (int)Math.pow(3, times_of_3) * (int)Math.pow(2, times_of_2);}
������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
