Lotto
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6806   Accepted: 4298

Description

In the German Lotto you have to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k > 6) of these 49 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 are 28 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 that reads in the number k and the set S and then prints all possible games choosing numbers only from S.

Input

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

Output

For each test case, print all possible games, each game on one line. The numbers of each game have to be sorted in ascending order and separated from each other by exactly one space. The games themselves have to be sorted lexicographically, that means sorted by the lowest number first, then by the second lowest and so on, as demonstrated in the sample output below. The test cases have to be separated from each other by exactly one blank line. Do not put a blank line after the last test case.

Sample Input

7 1 2 3 4 5 6 7
8 1 2 3 5 8 13 21 34
0

Sample Output

1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 4 5 6 7
1 3 4 5 6 7
2 3 4 5 6 7 1 2 3 5 8 13
1 2 3 5 8 21
1 2 3 5 8 34
1 2 3 5 13 21
1 2 3 5 13 34
1 2 3 5 21 34
1 2 3 8 13 21
1 2 3 8 13 34
1 2 3 8 21 34
1 2 3 13 21 34
1 2 5 8 13 21
1 2 5 8 13 34
1 2 5 8 21 34
1 2 5 13 21 34
1 2 8 13 21 34
1 3 5 8 13 21
1 3 5 8 13 34
1 3 5 8 21 34
1 3 5 13 21 34
1 3 8 13 21 34
1 5 8 13 21 34
2 3 5 8 13 21
2 3 5 8 13 34
2 3 5 8 21 34
2 3 5 13 21 34
2 3 8 13 21 34
2 5 8 13 21 34
3 5 8 13 21 34

Source

 
题意:枚举 排列组合
#include<cstdio>
using namespace std;
int s[],K;
int main(){
while(scanf("%d",&K)==&&K){
for(int i=;i<K;i++) scanf("%d",s+i);
for(int i=;i+<K;i++)
for(int j=i+;j+<K;j++)
for(int l=j+;l+<K;l++)
for(int m=l+;m+<K;m++)
for(int n=m+;n+<K;n++)
for(int o=n+;o+<K;o++)
printf("%d %d %d %d %d %d\n",s[i],s[j],s[l],s[m],s[n],s[o]);
printf("\n");
}
return ;
}

poj 2245 Lotto的更多相关文章

  1. poj 2245 Lotto(dfs)

    题目链接:http://poj.org/problem?id=2245 思路分析:无重复元素组合组合问题,使用暴力枚举法,注意剪枝条件. 代码如下: #include <iostream> ...

  2. poj 2245 水题

    求组合数,dfs即可 #include<cstdio> #include<iostream> #include<algorithm> #include<cst ...

  3. POJ 2245 Addition Chains(算竞进阶习题)

    迭代加深dfs 每次控制序列的长度,依次加深搜索 有几个剪枝: 优化搜索顺序,从大往下枚举i, j这样能够让序列中的数尽快逼近n 对于不同i,j和可能是相等的,在枚举的时候用过的数肯定不会再被填上所以 ...

  4. POJ 2245

    //此题一看便是简单的回溯题用DFS+回溯便可以做出来了. #include <iostream> #define MAXN 20 using namespace std; int _m[ ...

  5. POJ 2193 Lenny's Lucky Lotto Lists (DP)

    题目链接 题意 : 给你两个数N和M,让你从1到M中找N个数组成一个序列,这个序列需要满足的条件是后一个数要大于前一个数的两倍,问这样的序列有多少,输出. 思路 : dp[i][j]代表着长度为 i ...

  6. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  7. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  8. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

随机推荐

  1. C#实现图标批量下载

    本文略微有些长,花了好几晚时间编辑修改,若在措辞排版上有问题,请谅解.本文共分为四篇,下面是主要内容,也是软件开发基本流程. 阶段 描述 需求分析 主要描述实现本程序的目的及对需求进行分析,即为什么要 ...

  2. SarePoint Powershell Add user to Group

    $FromGroupnames = "001总经理","010101管理本部" $ToGroupname = "test" $SPWeb = ...

  3. UC如被百度控股,手机qq浏览器改如何进攻和防守

    很早以前在公司内部论坛里写的一篇文章,绯闻已经过过去了,现在已物事人物,UC已有阿里大靠山了. ----------------------------------------------- 据网络媒 ...

  4. [Android]ViewPager如何只初始化一个页面

    使用过ViewPager的应该都知道,ViewPager的setoffscreenpagelimit()方法,使用该方法可以设置在ViewPager滑动时,左右两侧各保存多少个页面,那我们直接设置se ...

  5. 【读书笔记】iOS网络-HTTP-URL百分号编码

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ty ...

  6. sql2008备份集中的数据库备份与现有的xxx数据库不同解决方法

    原文链接:http://wncbl.cn/posts/1993c22/ 问题描述 今天在配置一个 ASP 站点时,导入以前的数据库备份文件,提示:sql2008备份集中的数据库备份与现有的xxx数据库 ...

  7. android之apk反编译

    今天就来详细的讲一讲apk的反编译过程,之前自己一直没彻底搞清楚. 一.准备工作 反编译首先要准备三个工具.这三个工具都是可以百度下载的.就是下图所示的三个工具. 这三个工具是有各自作用的: (1)a ...

  8. 如何解决ajax跨域问题(转)

    由 于此前很少写前端的代码(哈哈,不合格的程序员啊),最近项目中用到json作为系统间交互的手段,自然就伴随着众多ajax请求,随之而来的就是要解决 ajax的跨域问题.本篇将讲述一个小白从遇到跨域不 ...

  9. Solr 参考资料

    solr 的入门好资料 https://cwiki.apache.org/confluence/display/solr/Apache+Solr+Reference+Guide https://two ...

  10. asp.net的心得体会

    1,gridview有点强大 2,页面的冗余代码有点多,性能略差. 3,access数据库的使用. 4,C/S端的开发,接触winform的开发 我自认为asp.net开发就像在一个别人限制好的画布上 ...