AC代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[11][11][11];
int record[100];
int DFS( int m, int n, int pre ){
if( m == 0 && n == 0 ){
// for( int i = 3; i >= 1; i-- ){
// cout << record[i] << " ";
// }
// cout << endl;
return 1;
}else if( n == 0 ){
return 0;
}
if( dp[m][n][pre] != -1 ){
return dp[m][n][pre];
}
int ans = 0;
for( int i = pre; i <= m; i++ ){
// record[n] = i;
ans += DFS( m - i, n - 1, i );
}
return dp[m][n][pre] = ans;
}
int main(){
int T, N, M;
memset( dp, -1, sizeof( dp ) );
cin >> T;
while( T-- ){
cin >> M >> N;
cout << DFS( M, N, 0 ) << endl;
}
return 0;
}