hdu1342 && POJ 2245 Lotto

Source: Internet
Author: User

LottoTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1755 Accepted Submission (s): 860


Problem DescriptionIn a Lotto I have 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 Input
7 1 2 3 4 5 6 78 1 2 3 5 8 13 21 340

Sample Output
1 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 3 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 341 2 5 8 21 34 1 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 342 3 5 8 13 21 2 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

Source

University of Ulm Local Contest 1996

#include <stdio.h> #include <string.h> #include <algorithm>using namespace std; int a[55],b[55],vis[55],k;void dfs (int c,int num) {if (num>6) {printf ("%d", b[1]), for (int i=2;i<=6;i++) printf ("%d ", B[i]);p rintf (" \ n ");} else{for (int i=c;i<k;i++) {if (!vis[i]) {B[num]=a[i];vis[i]=1;dfs (i,num+1); vis[i]=0;//num--;}}} int main () {int i,case=0;while (scanf ("%d", &k), k) {if (case++) printf ("\ n");//pe to Dead, for (i=0;i<k;i++) scanf ("%d" , &a[i]), sort (a,a+k), memset (vis,0,sizeof (Vis)), memset (b,0,sizeof (b));d FS (0,1); return 0;}


hdu1342 && POJ 2245 Lotto

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.