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 |
请问大牛们,这样算记忆化搜索吗?#include<iostream> using namespace std; int run(int a,int b); int a,b,c,d,e,f,g,h; int p[2000]; int Q(int i) { if(p[i]==1) return Q(i); if(i==0) { return a; p[i]=1; } if(i==1) { return b; p[i]==1; } if(i==2) { return c; p[i]=1; } if((i>=3)&&(i%2==1)&&(p[i]==0)) { return run((d*Q(i-1)+e*Q(i-2)-f*Q(i-3)),g); p[i]=1; } if((i>=3)&&(i%2==0)&&(p[i]==0)) { return run((f*Q(i-1)-d*Q(i-2)+e*Q(i-3)),h); p[i]=1; } } int run(int a,int b) { if(a>=0) return a%b; else return (b-(-a%b)); } int main() { int n,i,j,sum; cin>>n; memset(p,0,sizeof(p)); for(i=0;i<n;i++) { cin>>a>>b>>c>>d>>e>>f>>g>>h>>j; sum=Q(j); cout<<sum<<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