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)