http://acm.nyist.net/JudgeOnline/problem.php?pid=1058
A very simple problem, but a long time no AC out, looked at someone else's code, found that the difference between a variable of things, ah.
Program 17 Line: Originally I was starting from 0, after the submission time-out, changed to start from Cur, suddenly a miracle appeared. What a hole!!!
On the code:
1#include <stdio.h>2 intn,k;3 inta[ -],flag[ -];4 intsum;5 6 intDFS (intcur) {///returns 0 cur position not selectable return 1 found answer7 if(Sum >k)8 return 0;9 if(Sum = =k) {Tenprintf"yes\n"); One for(intj =0; J < N; J + +) A if(Flag[j] = =1) -printf"%d", A[j]); -printf"\ n"); the return 1; - } - for(inti = cur; I < n; i++){ - if(Flag[i] = =0){ +Flag[i] =1; -Sum + =A[i]; + intOK =DFS (i); A if(OK = =0){ atFlag[i] =0; -Sum-=A[i]; - } - if(OK = =1) - return 1; - } in } - return 0; to } + - intMainvoid){ the while(SCANF ("%d%d", &n,&k)! =EOF) { *sum =0; $ for(inti =0; I < n; i++){Panax Notoginsengscanf"%d",&a[i]); -Flag[i] =0; the } + if(! DFS (0)) Aprintf"no\n"); the } + -}
NYOJ-1058 Parts and issues