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 |
BFS 为何Runtime Error?#include <stdio.h> #include <string.h> int now,later,n,a[100]; struct P { int cur,p_pre; }q[10000]; void bfs() { now=-1; later=0; P head,i_s,j_s; head.cur=1; head.p_pre=-1; q[0]=head; while (1) { now++; i_s=q[now]; int i=now,j=now; while(i>=0) { j_s=i_s; while(j>=0) { later++; q[later].cur=q[i].cur+q[j].cur; q[later].p_pre=now; if (q[later].cur==n) return; j=j_s.p_pre; j_s=q[j_s.p_pre]; } i=i_s.p_pre; i_s=q[i_s.p_pre]; } } } void getflo() { a[0]=later; int i=1; while (q[later].p_pre!=0) { a[i++]=q[later].p_pre; later=q[later].p_pre; } a[i]=0; while(i) { printf("%d ",q[a[i]].cur); i--; } printf("%d\n",n); } int main() { while(scanf("%d",&n),n) { if(n>1) { bfs(); getflo(); } else printf("%d\n",n); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator