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

这是一个典型的dfs

代码:

#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
int num[100];
int chosed[100]; // 已经选择的数字
int k;
void find(int st, int n)//st:num[]的下表,用于从num[]数组中选择还未被选的数字      n:已经选了的个数
{int i;if(n == 6){int first = 1;for(i = 0; i < k; i++){if(chosed[i] == 1){if(first == 1){cout << num[i];first = 0;}else{cout << " " << num[i];}}}cout << endl;}for(i = st; i < k; i++){if(chosed[i] == 0){chosed[i] = 1;find(i + 1, n + 1);chosed[i] = 0;}}
}
int main()
{int first = 1;while(cin >> k){if(k == 0){break;}memset(num, 0, sizeof(num));for(int i = 0; i < k; i++){cin >> num[i];}if(first == 1) //除了第一排,其余的都要输出/n{first  = 0;}else{cout << endl;}memset(chosed, 0, sizeof(chosed));find(0, 0);}return 0;
}

poj2245Lotto相关推荐

最新文章

  1. 优秀的代码都是如何分层的?
  2. liteIDE配置环境变量
  3. 【Git】Git 修改刚提交的 commit message
  4. Apache Tika:通用的内容分析工具
  5. P5488 差分与前缀和(多项式/生成函数)
  6. JAVA入门级教学之(算数运算符)
  7. sqlyog怎么连接mysql错误2003_网站突然连不上,MySQL连接错误经常内存不够宕机
  8. cdr 表格自动填充文字_PS那些好用到哭的新手小技巧(1)——如何快速去除文字图片的水印或背景文字?...
  9. ubuntu中bash,sh,./,bash区别
  10. yii2 默认路由,默认动作
  11. 学习自己动手设计数据库
  12. Matlab系统辨识工具箱
  13. IDEA This inspection performs unresolved SQL references check
  14. 邮件发送平台哪个好?大家究竟该如何选择?
  15. 站在潮流前沿,不到100行代码快速实现一个简易版 vite
  16. 基于spss的多元回归分析模型
  17. 将图片转换成svg文件,自定义icon小图标,svg速成
  18. 招收2名远程学术实习生!1名硕士(2022春) 美国肯特州立大学认知机器人和人工智能实验室...
  19. 共模电压 matlab,三电平并网逆变器共模电压抑制方法研究
  20. Matlab中的linspace()函数

热门文章

  1. 四川翌加:抖音发日常和发作品哪里不一样
  2. 超级强烈推荐二十个超超超超超超超超超超超级极致走心的工具(呕心沥血搜寻到)
  3. cortellis数据库价格与价值分析
  4. 网易云音乐(2)————加载失败的原因
  5. 21/4/25 项目二:客户信息管理软件
  6. vue3+ts读取excel文件数据
  7. 吉林大学超星慕课高级语言程序设计课后作业(2022版)实验00
  8. IntellIJ IDEA导入项目后无法运行方法的解决方法!
  9. 制作nextcloud私人云盘
  10. 大旺中学2021年高考成绩查询,肇庆中学排名前十名,2021年肇庆中学排名一览表