Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
洪水#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator