leetcode343】的更多相关文章

Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. Example 1: Input: 2 Output: 1 Explanation: 2 = 1 + 1, 1 × 1 = 1. Example 2: Input:…
public class Solution { public int IntegerBreak(int n) { ) { ; } ) { ; } var max = int.MinValue; ; i <= n / ; i++) { var div = n / i; var mod = n % i; ; ) { cur = Convert.ToInt32(Math.Pow(i, div)); } else { ) * (i + mod)); var cur2 = Convert.ToInt32(…
思路: 将n不断拆分3出来直至其小于或等于4. 实现: class Solution { public: int integerBreak(int n) { ] = {, , , }; ) return a[n]; ; ) { p *= ; n -= ; } return p * n; } };…
题目详情 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 示例 1: 输入: 2 输出: 1 解释: 2 = 1 + 1, 1 × 1 = 1. 示例 2: 输入: 10 输出: 36 解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36. 说明: 你可以假设 n 不小于 2 且不大于 58. 题目解析 关键是找到状态方程, 我们设置dp[i]表示整数i的最大乘积, 那么把问题分成子问题, 我们发现dp[i] 与前面的dp…
Integer Break Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return…