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; const int INF=100000000; struct Que{ int num,step,pre; }que[1000002]; int BFS(int n) { int front=0,rear=0,minStep=INF,index; que[rear].num=que[rear].step=1; que[rear++].pre=-1; while(front<rear) { Que temp=que[front++]; if(temp.num==n && temp.step<minStep) { minStep=temp.step; index=front-1; continue; } int pre=front-1; while(pre!=-1) { int k=temp.num+que[pre].num; if(k<=n && temp.step+1<minStep) { que[rear].num=k; que[rear].step=temp.step+1; que[rear++].pre=front-1; } pre=que[pre].pre; } } return index; } void PRINT(int id) { if(que[id].pre!=-1) PRINT(que[id].pre); printf("%d ",que[id].num); } int main() { int n; while(scanf("%d",&n) && n!=0) { PRINT(BFS(n)); printf("\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