【LeetCode】343.整数拆分

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time: 2019/3/18
# @Author: xfLi
# The file...

def integerBreak(n):
    if n < 4:
        return n - 1
    dp = [0] * (n+1)
    dp[2] = 2
    dp[3] = 3
    for i in range(4, n+1):
        dp[i] = max(3 * dp[i - 3], 2 * dp[i -2])
    return dp[n]

if __name__ == '__main__':
    n = 10
    result = integerBreak(n)
    print(result)

 

你可能感兴趣的:(python,算法)