Lotto

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1411    Accepted Submission(s): 697
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.

 
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

简单的深搜,话说这题的输出格式真的好奇葩啊。。

#include <stdio.h>
int arr[14], vis[14], n, store[6], id, blank; void DFS(int k){
if(id == 6){
for(int i = 0; i < 6; ++i)
if(i == 0) printf("%d", store[i]);
else printf(" %d", store[i]);
printf("\n"); return;
}
for(int i = k; i < n; ++i){
if(!vis[i]){
store[id++] = arr[i];
vis[i] = 1; DFS(i + 1);
vis[i] = 0; --id;
}
}
} int main(){
while(scanf("%d", &n), n){
for(int i = 0; i < n; ++i){
scanf("%d", arr + i);
vis[i] = 0;
}
if(blank) printf("\n");
id = 0; DFS(0);
++blank;
}
return 0;
}

HDU1342 Lotto 【深搜】的更多相关文章

  1. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  2. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  3. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  4. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  5. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  6. 深搜+回溯 POJ 2676 Sudoku

    POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538 ...

  7. 深搜+DP剪枝 codevs 1047 邮票面值设计

    codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description ...

  8. 【wikioi】1049 棋盘染色(迭代深搜)

    http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...

  9. poj1190 生日蛋糕(深搜+剪枝)

    题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...

随机推荐

  1. Yaha,Yaho

    Yaha: Yaho: 听雪楼上听雪落,雪落无声空余楼. 同样的地方,一坐三年多,人走楼空,回顾空留. 自己非常白痴地画着苹果,非常嗨森地逗自己玩. 这两层精致的书库是大学里面能容纳我的地方(ABC的 ...

  2. 【浅墨著作】《OpenCV3编程入门》内容简单介绍&amp;勘误&amp;配套源码下载

    经过近一年的沉淀和总结,<OpenCV3编程入门>一书最终和大家见面了. 近期有为数不少的小伙伴们发邮件给浅墨建议最好在博客里面贴出这本书的文件夹,方便大家更好的了解这本书的内容.事实上近 ...

  3. 买面包和IoC

    今天上午准备去一个阿姨,在那里买面包.这可能是由于小尺寸她的,因此,管理不规范,所以,当你买面包.没有人行.即使所有的大学生,似几乎没有这种意识.. . 但让我感到震惊的是.尽管没有排队,但阿姨似乎能 ...

  4. CSDN Androidclient生产 导航帖

    弄个导航棒.的相关知识汇总. CSDN Android的client的效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG1qNjIzNTY1Nzk ...

  5. 国内Android应用推广的六大主流方式

    国内Android应用推广的六大主流方式 http://mobi.baike.com/article-19433.html 随着Android市场份额的飞速增长,越来越多的国内开发团队和公司開始投入A ...

  6. SVN目录对号图标(更新、冲突)不显示

    长谈想知道,大约SVN这些冲突.变化.加入.不显示问题etc目录下的复选图标,退房的在线信息,多数说的更改icon的settings,后来,一点点仔细阅读SVN配有英文说明文档,我相信,改变是有点问题 ...

  7. Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数

    Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数 关于处理小数点位数的几个oracle函数()1. 取四舍五入的几位小数select round(1.2345, 3) fr ...

  8. java.lang.IllegalStateException: You need to use a Theme.AppCompat theme

    配置: 中设置theme为 <application android:allowBackup="true" android:icon="@mipmap/ic_lau ...

  9. Power Strings (poj 2406 KMP)

    Language: Default Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33205   ...

  10. 设计模式Template Method模式(Template Method)摘录

    23种子GOF设计模式一般分为三类:创建模式.结构模型.行为模式. 创建模式抽象的实例.怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而一个对象创建型模式将实例化托付给还 ...