打表就行了,肯定不会TLE.
#include
const int MAXN = 2001;
const int MAXM = 2001;
int f[MAXN][MAXM];
int main()
{
int i,j ;
for( i = 0 ; i < MAXN ; i++ )
{
f[1][i] = f[i][1] = i;
}
for( i = 2 ; i < MAXN ; i++ )
{
for( j = 2; j < MAXM; j++ )
{
f[i][j] = f[i-1][j] + f[i][j-1];
}
}
int n;
while( scanf("%d",&n)!=EOF)
{
int a,b;
while(n-- && scanf("%d%d",&a,&b) )
printf("%dn",f[a][b]);
}
return 0;
}