leetcode 343

来源:互联网 发布:网络兼职什么项目最好 编辑:程序博客网 时间:2024/04/28 14:52
  1. 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 36 (10 = 3 + 3 + 4).

Note: you may assume that n is not less than 2.

class Solution {public:    int an[10000];    int bn[10]={0,0,1,2,4,6,9,12,18,27};    int integerBreak(int n) {        int temp;        an[0]=0;        an[1]=1;        an[2]=2;        an[3]=3;        an[4]=4;        if(n<=5){            return bn[n];        }        else{            for(int i=5;i<=n;i++){                an[i]=an[3]*an[i-3];            }        }        return an[n];    }};
0 0