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

记忆化搜索,0ms

Posted by KatrineYang at 2016-09-08 09:09:59 on Problem 1283
#include <iostream>
#include <stdio.h>
using namespace std;

long long int dp[202][202] = {0};

long long int getAns(int k, int m){
	if(dp[k][m] != 0) return dp[k][m];
	if(m == 0 || k == 1) return 1;
	long long int ans = 0;
	for(int s = 1; s <= m && s <= k; s++){
		ans += getAns(s, m-s);
	}
	dp[k][m] = ans;
	return ans;
}

int main() {
	int n,k;
	while(1){
		scanf("%d%d", &n, &k);
		if(n==0 && k==0) break;
		int m = n-k;
		printf("%I64d\n", getAns(k,m));
	}
	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