1. 程式人生 > >整數拆分

整數拆分

wikipedia dia code pac += tar sin 拆分 cnblogs

wiki上看到了一個厲害的遞推式

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main() {
 5     const int len = 121;
 6     int num[len + 1] = { 1 };
 7 
 8     for (int i = 1; i <= len; ++i)
 9         for (int j = i; j <= len; ++j)
10             num[j] += num[j - i];
11 
12     for (int i = 0
; i <= len; i++) 13 cout << i << << num[i] << endl; 14 return 0; 15 }

整數拆分