直接代码吧:
/*Hdu 1028 Ignatius and the Princess III
整数划分
*/
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 150;
int f[maxn][maxn];
int n;
int main()
{
while(cin>>n)
{
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++) f[i][j] = 0;
f[1][1] = 1;
for(int i = 2; i <= n; i++)
{
for(int j = 1; j <= i; j++)
{
if( j!=i ) f[i][j] = f[i][j-1] + f[i-j][j];
else f[i][j] = f[i][j-1] + 1;
if(i > j) f[j][i] = f[j][j];
}
}
cout<<f[n][n]<<endl;
}
return 0;
}