Hdu 1342.. Review wide search by the way, practice a brain stump format

Source: Internet
Author: User

In a Lotto I had ever played, one had to select 6 numbers from the set {,..., 49}. A popular strategy to play Lotto-although it doesn ' t increase your chance of Winning-is to select a subset S containin G K (k>6) of these numbers, and then play several games with choosing numbers only from S. For example, for k=8 and S = {1,2,3,5,8,13,21,34} There is possible games: [1,2,3,5,8,13], [1,2,3,5,8,21], [1,2,3,5,8, 34], [1,2,3,5,13,21], ... [3,5,8,13,21,34].

Your job is to write a program this reads in the number k and the set S and then prints all possible games choosing number s only from S.

Inputthe input file would contain one or more test cases. Each of the test case consists of the one line containing several integers separated is from each of the other by spaces. The first integer on the line would be the number K (6 < K < 13). then k integers, specifying the set S, would follow in ascending order. Input would be terminated by a value of zero (0) for K.

Outputfor each of the test case, the print all possible games, and the game on one line. The numbers of each game has the to is sorted in ascending order and separated from each other by exactly one space. The games themselves has to be sorted lexicographically, which means sorted by the lowest number first and then by the second Lowest and so on, as demonstrated in the sample output below. The test cases has the to is separated from each and the exactly one blank line. Don't put a blank line after the last test case.

Sample Input7 1 2 3 4 5 6 78 1 2 3 5 8 13 21 340

Sample OUTPUT1 2 3 4 5 61 2 3 4 5 71 2 3 4 6 71 2 3 5 6 71 2 4 5 6 71 3 4 5 6 72 3 4 5 6 71 2 3 5 8 131 2 3 5 8 211 2 3 5 8 341 2 3 5 13 211 2 3 5 13 341 2 3 5 21 341 2 3 8 13 211 2 3 8 13 341 2 3 8 21 341 2 3 13 21 341 2 5 8 13 211 2 5 8 13 34 1 2 5 8 21 341 2 5 13 21 341 2 8 13 21 341 3 5 8 13 211 3 5 8 13 341 3 5 8 21 341 3 5 13 21 341 3 8 13 21 341 5 8 13 21 34 2 3 5 8 13 212 3 5 8 13 342 3 5 8 21 342 3 5 13 21 342 3 8 13 21 342 5 8 13 21 343 5 8 13 21 34 Here's The pit Daddy. Format problem is not required at the last output separated by a space.   ~ Here's a little trick of int i,flag=1;
while (cin>>t)
{
if (t==0) break;
if (flag) flag=0;
else cout<<endl; The approximate idea of each output at the beginning of the output space and the first time the output is not required spaces here, the value of the flag is adjusted to determine whether the subsequent output is 0 before the output operation

#include <iostream>
#include <string.h>
#include <cstdio>
#include <algorithm>
using namespace Std;
int num[100],ans[100],t;
BOOL CMP (int x,int y)
{
Return x<y;
}
void Dfs (int time,int position)
{
int i;
if (time==7)
{
for (i=1;i<time;i++)
{
if (i==1) printf ("%d", ans[i]);
else printf ("%d", ans[i]);
}
cout<<endl;
Return
}
for (i=position+1;i<=t;i++)
{
Ans[time]=num[i];
cout<< ' < ' <<ans[time]<< ' > ';
DFS (time+1,i);
}
}
int main ()
{
int i,flag=1;
while (cin>>t)
{
if (t==0) break;
if (flag) flag=0;
else cout<<endl;
for (i=1;i<=t;i++)
{
cin>>num[i];
}
Sort (num+1,num+t,cmp);
for (i=1;i<=t;i++) cout<<num[i];
memset (vis,0,sizeof (VIS));
Vis[1]=1;
DFS (1,0);
}

return 0;
}

Hdu 1342.. Review wide search by the way, practice a brain stump format

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.