题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398
题目大意:条件:有无限个1^2, 2^2, 3^2, 4^2......17^2 输入:n 输出:由条件有多少种组成方法使和为n
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cstdlib> 6 #include <cmath> 7 #include <set> 8 #include <map> 9 #include <vector> 10 using namespace std; 11 12 int main() 13 { 14 int n, i, j, k, a[400], b[400]; 15 while(~scanf("%d", &n)) 16 { 17 if(n == 0) 18 break; 19 for(i = 0; i <= n; i++) 20 { 21 a[i] = 1; 22 b[i] = 0; 23 } 24 for(i = 2; i <= 17; i++) 25 { 26 for(j = 0; j <= n; j++) 27 { 28 for(k = 0; k + j <= n; k += i * i) 29 { 30 b[k + j] += a[j]; 31 } 32 } 33 for(j = 0; j <= n; j++) 34 { 35 a[j] = b[j]; 36 b[j] = 0; 37 } 38 } 39 printf("%d ", a[n]); 40 } 41 return 0; 42 }