NYOJ-1058 Parts and issues

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.