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 0810311106 at 2009-11-01 16:51:31 on Problem 2696
注意题中的mod的定义部分是r从0到q-1,当满足后面的条件时就取此时的r作为mod的结果~!

#include"iostream"
using namespace std;
int mod(int a,int b)
{
	int r;
	for(r=0;r<=b-1;r++)
		if((a-r)%b==0)
			return r;
}
int main()
{
	int n;
	cin>>n;
	 while(n--)
	 {
		 int a,b,c,d,e,f,g,h,i;
		 int s[1001],k;
		 cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
		 s[0]=a;
		 s[1]=b;
		 s[2]=c;
		 for(k=3;k<=i;k++)
			 if(k%2==0)
				 s[k]=mod(f*s[k-1]-d*s[k-2]+e*s[k-3],h);
			  else
				  s[k]=mod(d*s[k-1]+e*s[k-2]-f*s[k-3],g);
		 cout<<s[i]<<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