http://acm.timus.ru/problem.aspx?space=1&num=1017
题意:有n块砖,要求按照严格递增的个数摆放成楼梯,求楼梯的摆放种类数。
思路:状态转移方程:dp[i][j]=sum(dp[i-j][k]), 0 < k < j; i 表示砖的总数,j表示最高的那层的个数。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <stdio.h> 2 #include <string.h> 3 #define LL long long 4 const int N=502; 5 LL dp[N][N]; 6 int main() 7 { 8 int n; 9 while(~scanf("%d",&n)) 10 { 11 memset(dp,0,sizeof(dp)); 12 for (int i = 1; i <= n; i++) 13 dp[i][i] = 1; 14 dp[3][2] = 1; 15 dp[4][3] = 1; 16 for (int i = 5; i <= n; i++) 17 { 18 for (int j = 1; j < i; j++) 19 { 20 for (int k = 1; k < j; k++) 21 dp[i][j]+=dp[i-j][k]; 22 } 23 } 24 LL ans = 0; 25 for (int i = 1; i < n; i++) 26 ans+=dp[n][i]; 27 printf("%lld\n",ans); 28 } 29 return 0; 30 }