Problem Description
In a Lotto I have ever played, one has 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 file 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. 
 
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace::std; int map[];
int a[],k=; void dfs(int n, int m)
{
if(n == )
{
for(int i= ;i<n;i++)
{
if(i)
printf(" "); printf("%d",a[i]);
}
printf("\n");
return ;
}
if(m >= k)
return ;
a[n] = map[m];
dfs(n+,m+); //自底向上递归
dfs(n,m+);
} int main()
{
int t = ;
while(scanf("%d",&k) && k != )
{
memset(map,,sizeof(map));
memset(a,,sizeof(a)); if(t != )
printf("\n"); //最后的输出结果和输入 0 之间不能有空行
for(int i=; i<k;i++)
{
scanf("%d",&map[i]);
}
dfs(,);
t++;
} return ;
}

HDOJ.1342 Lotto (DFS)

hdoj - 1342 Lotto的更多相关文章

  1. HDOJ.1342 Lotto (DFS)

    Lotto [从零开始DFS(0)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of ...

  2. hdoj 1342 Lotto【dfs】

    Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. HDOJ(HDU).2266 How Many Equations Can You Find (DFS)

    HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...

  4. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  5. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  6. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  7. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

  8. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  9. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

随机推荐

  1. css,对包含有子元素的元素进行flex后,会影响原有的布局。如何后续处理

    对包含有子元素的元素进行flex后,会影响原有的布局. 例如设置两个div,第一个div包含一个img(图片),第二个div包含多个p元素(对前面的img的说明).如下图 1:当对着两个两个div进行 ...

  2. VUE回顾基础3

    1.方法 在vue模板里函数被定义为方法来使用,将函数放在methods对象里,作为一个属性,就可以在模板里使用它 this:在方法中this指向该方法所属的组件,可以使用this方文档data对象的 ...

  3. 用 node.js 模仿 Apache 的部分功能

    首先,这个例子用到了服务端渲染的技术.服务端渲染,说白了就是在服务端使用模板引擎,这里我先简单的介绍一下服务端渲染与客户端渲染之间的区别. 服务端渲染与客户端渲染之间的区别: 客户端渲染不利于搜索引擎 ...

  4. Python——生成器&推导式

    生成器 生成器的本质就是迭代器,那么还为什么有生成器呢,两者唯一的不同就是迭代器都是Python给你提供能够的已经写好的工具或者通过数据转化得来的.而生成器是需要我们自己用Python代码构建的工具. ...

  5. QuickStart系列:Docker部署PostgreSQL

    docker镜像地址: https://hub.docker.com/_/postgres/ https://www.widuu.com/chinese_docker/examples/postgre ...

  6. shell输出文本颜色

    绿地白字 echo -e "\033[42;37m 绿底白字 \033[0m"

  7. 自定义View(二),强大的Canvas

    本文转自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1212/703.html Android中使用图形处理引擎,2D部分是 ...

  8. termux 为 python3 添加 numpy 库

    1 本机环境 Termux v0.77 python3.8 2 配置步骤 2.1 安装 python 和 ipython apt updateapt upgradepkg install python ...

  9. 在本地调用hadoop的api

    第一次在本地运行Java代码,调用hadoop的hdfs的api接口,遇到下面的问题: 1.HADOOP_HOME and hadoop.home.dir are unset 解决办法:在本地安装配置 ...

  10. @Scope("prototype")

    spring中bean的scope属性,有如下5种类型: singleton 表示在spring容器中的单例,通过spring容器获得该bean时总是返回唯一的实例prototype表示每次获得bea ...