Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:递归超时啊?怎么办?高人帮忙啊。。。In Reply To:递归超时啊?怎么办?高人帮忙啊。。。 Posted by:ppdg_error at 2006-02-20 11:48:51 > #include <iostream> > using namespace std; > inline int fai(int a,int b,int c,int d,int e,int f,int g,int h,int i){ > int temp; > if(i==0){return a;} > if(i==1){return b;} > if(i==2){return c;} > if((i>=3)&&(i%2==1)){ > temp=d*fai(a,b,c,d,e,f,g,h,i-1)+e*fai(a,b,c,d,e,f,g,h,i-2)-f*fai(a,b,c,d,e,f,g,h,i-3); > while(temp<0){ > temp=temp+g; > > } > return temp%g; > } > if((i>=3)&&(i%2==0)){ > temp=f*fai(a,b,c,d,e,f,g,h,i-1)-d*fai(a,b,c,d,e,f,g,h,i-2)+e*fai(a,b,c,d,e,f,g,h,i-3); > while(temp<0){ > temp=temp+h; > > } > return temp%h; > } > } > int main() > { > int a,b,c,d,e,f,g,h,i,num,count=1; > cin>>num; > while(count<=num){ > cin>>a>>b>>c>>d>>e>>f>>g>>h>>i; > cout<<fai(a,b,c,d,e,f,g,h,i)<<endl; > count++; > } > system("PAUSE"); > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator