Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator