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

776K 0ms 水过

Posted by KatrineYang at 2016-08-17 02:46:06 on Problem 1221 and last updated at 2016-08-17 02:49:17
我的递推公式:
P(n,m)=1(当n=m或n=2m时),
      =0(当n/2<m<n时),
      =\sigma_{l\geq m}P(n-2m, l)(其他情况)
其中,P(n,m)为和为n两端的数为m的序列个数
然后记忆化搜索就可以了

#include <stdio.h>
bool jsed[300][300] = {false};
long long int jg[300][300];

long long int getAns(int n, int m){
	if(m==n || n==2*m) return 1;
	if(m > n/2) return 0;
	if(jsed[n][m]) return jg[n][m];
	long long int res = 0;
	if(n >= 3*m) res += 1;
	for(int l = m; n >= 2 * (l+m); l++) res += getAns(n-2*m, l);
	jsed[n][m] = true;
	jg[n][m] = res;
	return res;
}

int main() {
	while(1){
		int n;
		scanf("%d", &n);
		if(n == 0) return n;
		long long int res = 0;
		for(int i = 1; i <= n/2; i++) res += getAns(n, i);
		res += 1;
		printf("%d %I64d\n", n, res);
	}
	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