hoj1090The Staircases
做完整数划分那题后,现在感觉这道题很简单,状态转移方程为
dp[i][j] = dp[i][i] j>i
= dp[i-j][j-1]+dp[i][j-1]
建议看看我的博客上的hoj1402题
#include <iostream>
#include <cstring>
using namespace std;
#define X 510
long long dp[X][X],n;
void init()
{
memset(dp,0,sizeof(dp));
for(int i=1;i<X;i++) //初始化
{
dp[1][i] = 1;
dp[0][i] = 1;
}
for(int i=2;i<X;i++) //状态转移方程
for(int j=1;j<X;j++)
if(i<j)
dp[i][j] = dp[i][i];
else
dp[i][j] = dp[i][j-1]+dp[i-j][j-1];
}
int main()
{
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
init();
while(cin>>n,n)
cout<<dp[n][n]-1<<endl;
return 0;
}