HDU 2160 Sequence One (DFS)

Source: Internet
Author: User

1#include <iostream>2#include <vector>3#include <algorithm>4#include <cstdio>5#include <memory.h>6 using namespacestd;7 #defineMAXN 200028 9 Ten //applies to positive integers OneTemplate <classT> AInlinevoidScan_d (T &ret) { -     CharC ret=0; -      while((C=getchar ()) <'0'|| C>'9'); the      while(c>='0'&&c<='9') ret=ret*Ten+ (C-'0'), c=GetChar (); - } -  - inta[1010]; + intCNT; - intans[1010]; + inttot; A intN, K; at intFlag; -  - intCheckintIintJ//Check to see if there are any numbers - { -      while(I <j) -         if(a[i++] = =A[j]) in         return 0; -     return 1; to } +  - voidDfsintNowintnum) the { *     inti; $     if(num = =tot) {Panax Notoginseng++CNT; -          for(i =0; I < tot-1; ++i) theprintf"%d", Ans[i]); +printf"%d\n", ans[tot-1]); A         if(cnt = = k) flag =1; the         return; +     } -     if(num = =0) {//The first time there is no previous number, special handling $          for(i =0; i < n; ++i) { $             if(Check (0, i)) { -Ans[num] =A[i]; -DFS (I,1); the                 if(flag)return; -             }Wuyi         } the}Else { -          for(i = Now +1; i < n; ++i) { Wu             if(A[i] >= A[now] && check (now+1, i)) { -Ans[num] =A[i]; AboutDFS (I,num +1); $                 if(flag)return; -             } -         } -     } A } +  the intMain () - { $     intI, t; the      while(~SCANF ("%d%d",&n,&k)) { the          for(i =0; i < n; ++i) the Scan_d (A[i]); theCNT =0; -          for(tot =1; CNT < k; ++tot) { inFlag =0; thet =CNT; theDfs0,0); About             if(t = CNT | | flag) Break;//meet the number of requirements or finish all possible scenarios the         } thePuts""); the     } +     return 0; -}
code June

HDU 2160 Sequence One (DFS)

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.