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 zhu4800448 at 2010-08-26 20:02:23 on Problem 1664 and last updated at 2010-08-26 20:05:13
思路是模拟构造非降序列(这样才能不重复),统计其个数
dfs(i,p,j)
//i:放苹果的位置,
//p:第i个位置放的苹果的个数,用来做后面的最底限,以构造‘非降’序列
//还剩了j个苹果可以放
#include<iostream>
using namespace std;
int n,m,ans;
void dfs(int i,int p,int j)
{
	int k;
	if(i==m-1)
	{
		ans++;
		return;
	}
	for(k=p;2*k<=j;k++)//“2*k<=j”这个地方弄了不少时间,k<=j-k才是不降序列
		dfs(i+1,k,j-k);
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ans=0;
		cin>>n>>m;
		dfs(0,0,n);
		cout<<ans<<endl;
	}
	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