leetcode 343

通过观察只要拆出足够多的3即可,可以利用前面的进行递推,

这里有一个证明为什么拆成大于3的好:http://blog.csdn.net/liyuanbhu/article/details/51198124

 1 class Solution {
 2 public:
 3     int integerBreak(int n) {
 4         vector<int>k(60,0);
 5          k[2]=1;k[3]=2;k[4]=4;k[5]=6;k[6]=9;
 6         if(n>=2&&n<=6)
 7         return k[n];
 8         int i,num=3;
 9         for(i=7;i<=n;i++) 
10             k[i]=num*k[i-3];
11         return k[n];
12     }
13 };
原文地址:https://www.cnblogs.com/thefirstfeeling/p/5731759.html