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 |
贴个代码(记忆递归,普通递归行不通):注意题中的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator