Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 洪水

Posted by KatrineYang at 2016-08-23 01:00:38 on Problem 1664
```#include <iostream>
#include <stdio.h>
using namespace std;

int dp[20][20][20];

void init(){
for(int i = 0; i < 20; i++)
for(int j = 0; j < 20; j++)
for(int k = 0; k < 20; k++)
dp[i][j][k] = -1;
}

int getAns(int M, int N, int mx){
if(dp[M][N][mx] != -1) return dp[M][N][mx];
if(N < M || N > M*mx || mx > N) return 0;
if(M == 1){
if(N == mx) return 1;
else return 0;
}
int res = 0;
for(int t = 1; t <= mx; t++){
res += getAns(M-1, N-mx, t);
}
dp[M][N][mx] = res;
return res;
}

int main() {
init();
int T;
scanf("%d", &T);
for(int i = 0; i < T; i++){
int M, N;
scanf("%d%d", &M, &N);
int n = M;
int ans = 0;
for(int m = 1; m <= N; m++){
for(int mx = (n-1)/m+1; mx <= n; mx++){
ans += getAns(m, n, mx);
}
}
printf("%d\n", ans);
}
return 0;
}
```

Followed by: