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)

最新文章

  1. scala练习题1 基础知识
  2. ASP.NET MVC 概述
  3. 字符串中判断存在的几种模式和效率(string.contains、string.IndexOf、Regex.Match)
  4. java字符编码和oracle乱码
  5. CANopen DS301协议中文翻译V03版
  6. BZOJ-1927 星际竞速 最小费用最大流+拆点+不坑建图
  7. MakePic.com 图片制造 打造个性签名 拒绝垃圾邮件 生成个性印章
  8. Delphi判断进程是否存在(使用CreateToolhelp32Snapshot)
  9. Dialog 不能全屏,左右有间距解决方案
  10. 注意事项: Solr设备 Hello World
  11. 浅读K-means
  12. 测试体验Centrifugo
  13. 微信退款时候报”请求被中止: 未能创建 SSL/TLS 安全通道“或”The request was aborted: Could not create SSL/TLS secure channel“的错误
  14. js大图轮播和倒计时
  15. asp.net 获取 repeater checkbox 值
  16. Introducing DataFrames in Apache Spark for Large Scale Data Science(中英双语)
  17. 结构体地址 字符串地址 数组地址 辨析 字符char是整型 内存地址
  18. layer.load()加载层如何加入文字描述
  19. python + docker, 实现天气数据 从FTP获取以及持久化(二)-- python操作MySQL数据库
  20. 深度包检测(DPI)详细介绍

热门文章

  1. guava使用
  2. MySQL-By孙胜利-sifangku.com
  3. DOS命令_查询某个端口的占用情况并释放
  4. Windows10家庭版安装docker攻略
  5. 前端jQurey
  6. 18道kafka高频面试题哪些你还不会?(含答案和思维导图)
  7. java中的偏序关系
  8. 日志聚合工具loki
  9. CentOS7怎样安装Redis4.0.12
  10. 记一次用pip安装docker-compose报错及解决方法