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. 【转载】C#中List集合使用LastIndexOf判断元素最后一次出现的索引位置

    在C#的List集合操作中,有时候需要判断元素对象在List集合中第一次出现的索引位置信息,此时需要使用到List集合的IndexOf方法来判断,如果元素存在List集合中,则IndexOf方法返回所 ...

  2. springCloud学习5(Spring-Cloud-Stream事件驱动)

    springcloud 总集:https://www.tapme.top/blog/detail/2019-02-28-11-33 代码见文章结尾   想想平常生活中做饭的场景,在用电饭锅做饭的同时, ...

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

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

  4. Git管理修正(取消跟踪、合并commit)

    本文总结了最近使用Git时候遇到的两个问题: 1. 当将不必要跟踪的文件加入到仓库后如何处理? 2. 提交了多个功能相同的commit后如何处理? 总结经验 在创建仓库的一开始,就要设置号.gitig ...

  5. C# DataTable 和List之间相互转换的方法(转载)

    来源:https://www.cnblogs.com/shiyh/p/7478241.html 一.List<T>/IEnumerable转换到DataTable/DataView 方法一 ...

  6. Oracle Block Cleanouts 块清除

    当用户发出提交(commit)之后,oracle是需要写出redo来保证故障时数据可以被恢复,oracle并不需要在提交时就写出变更的数据块.由于在事务需要修改数据时,必须分配ITL事务槽,必须锁定行 ...

  7. rancheros在vm主机部署

    问题描述: 容器化,越来越重要.在云服务中很大比例的服务都跑在容器中,今天介绍rancheros基于容器的os. 特点: 启动快,比较小系统服务也是基于容器化 使用最新的docker release ...

  8. Linux 系统安全相关

    本篇关于Linux的一些安全知识,主要就是与账号相关的安全. 账户文件锁定 当服务器中的用户账号已经固定,不在进行更改,可锁定账户文件.锁定后,无法添加.删除账号,也无法更改密码等. 锁定账户文件 c ...

  9. Docker-compose(创建容器)

    Docker-compose(创建容器) 本文原始地址:https://sitoi.cn/posts/23955.html 样例 version: "2" services: sp ...

  10. 2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心

    2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心 [Proble ...