题目:http://poj.org/problem?id=1664
分析:DP.就是一个整数划分模型.
代码:
#include <cstdio>
#include <algorithm>
using namespace std;
const int Tmax=20;
int f[Tmax][Tmax];
int dp(int m,int n)
{
if(f[m][n]>0) return f[m][n];
if(n<1||m<1) return 0;
if(n==1||m==1) return f[m][n]=1;
if(n>m) return f[m][n]=dp(m,m);
if(n==m) return f[m][n]=1+dp(m,n-1);
return f[m][n]=dp(m,n-1)+dp(m-n,n);
}
int main()
{
int T,m,n;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
printf("%d\n",dp(m,n));
}
return 0;
}