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 |
n最大到300呀,像这种回朔只能对付n=8以内的吧,我觉得!!!!In Reply To:大家看看为什么我的回溯会超时啊 Posted by:dzs8819 at 2007-06-09 16:27:29 > #include<iostream> > #include<math.h> > using namespace std; > > int main() > { > int n,a[302]; > int i,j; > bool f; > while(scanf("%d",&n) && n!=0) > { > for(i=1;i<=n;i++) > a[i]=0; > for(i=1;i<=n;i++) > { > a[i]++; > f=false; > for(j=1;j<i;) > if(a[i]>n) > { > f=true; > a[i]=0; > break; > } > else > if(a[i]==a[j] || fabs(a[i]-a[j])==i-j) > { > j=1; > a[i]++; > } > else > j++; > if(f) > i-=2; > } > for(i=1;i<=n;i++) > if(i<n) > printf("%d ",a[i]); > else > printf("%d\n",a[i]); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator