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 |
Re:觉得应该可以,可以过Sample,但WA了,请教有什么没考虑好的,谢谢In Reply To:不知道可不可以简化成这样搜 Posted by:PC0400322032 at 2004-08-13 17:19:59 > #include <stdio.h> > int v[5],a[6]; > bool dfs(int k,int m) > { > if(k==4) > { > if(m==a[4]) > return 1; > else > return 0; > } > for(int i=0;i<4;i++) > if(v[i]==0) > { > v[i] = 1; > if(dfs(k+1,m*a[i])) > return 1; > if(dfs(k+1,m+a[i])) > return 1; > if(dfs(k+1,m-a[i])) > return 1; > if(a[i]!=0) > { > if(dfs(k+1,m/a[i])) > return 1; > } > v[i] = 0; > } > return 0; > } > bool done() > { > for(int i=0;i<4;i++) > { > v[i] = 1; > if(dfs(1,a[i])) > return 1; > } > return 0; > } > void main() > { > int i; > while(1) > { > scanf("%d",&a[0]); > if(a[0]<0) > break; > v[0] = 0; > for(i=1;i<5;i++) > { > scanf("%d",&a[i]); > v[i] = 0; > } > for(i=0;i<5;i++) > printf("%d ",a[i]); > if(done()) > printf("OK!\n"); > else > printf("NO!\n"); > } > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator