设dp[ i ][ j ]为i个苹果放进j个盘子里,则
i == j 时,dp[ i ][ j ] = dp[ i ][ j - 1 ] + 1;
i < j:肯定有空盘子且0 5这种放法与 5 0相同,故dp[ i ][ j ] = dp[ i ] [ i ];
i > j 时:dp[ i ][ j ] = dp[ i - j ] [ j ] + dp[ i ] [ j - 1];
#include<stdio.h>
#include<string.h>
#define N 15
int dp[N][N];
int main()
{
memset(dp, 0, sizeof(dp));
for( int i = 1; i <= 10; i ++ )
{
dp[i][1] = dp[1][i] = 1;
}
for (int i = 2; i <= 10; i++)
{
for ( int j = 2; j <= 10; j++)
{
if( i > j )
{
dp[i][j] = dp[i-j][j] + dp[i][j-1];
}
else if( i < j )
dp[i][j] = dp[i][i];
else
dp[i][j] = dp[i][j-1] + 1;
}
}
int y, t, x;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &x, &y);
printf("%d\n", dp[x][y]);
}
return 0;
}