Lotto

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2933    Accepted Submission(s): 1386

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
题意很简单 给你一个长度为k(>=6)的序列 
让你输出一个长度为6的序列(递增)且这个序列至少要有一个数大于等于6
 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<queue>
#include<cstring>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
int a[15],b[15];
int visited[15],n;
void DFS(int t,int num)
{
if(num==6)
{
for(int i=0;i<5;i++)
printf("%d ",b[i]);
printf("%d\n",b[5]);
return;
}
for(int i=t;i<n;i++)
{
if(visited[i]==0)
{
visited[i]=1;
b[num]=a[i];
DFS(i+1,num+1);
visited[i]=0;
}
}
} int main()
{
int tt=0;
while(scanf("%d",&n)!=EOF)
{
if(n==0)break;
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
if(tt)cout<<endl;
tt++;
memset(visited,0,sizeof(visited));
DFS(0,0);
}
return 0;
}
 

hdu 1342(DFS)的更多相关文章

  1. F - JDG HDU - 2112 (最短路)&& E - IGNB HDU - 1242 (dfs)

    经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬 ...

  2. F - Auxiliary Set HDU - 5927 (dfs判断lca)

    题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...

  3. hdu - 1072(dfs剪枝或bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 思路:深搜每一个节点,并且进行剪枝,记录每一步上一次的s1,s2:如果之前走过的时间小于这一次, ...

  4. HDU——2647Reward(DFS或差分约束)

    Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. P - Sudoku Killer HDU - 1426(dfs + map统计数据)

    P - Sudoku Killer HDU - 1426 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为 ...

  6. hdu 1142(DFS+dijkstra)

    #include<iostream> #include<cstdio> #include<cmath> #include<map> #include&l ...

  7. hdu 1015(DFS)

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

  8. hdu 1181(DFS)变 形 课

    变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submis ...

  9. J - Assign the task - hdu 3974(DFS建树+简单线段树)

    题意:给一些节点简单额对应关系,可以组成一个树,如果树的某一个节点更新那么他的所有子节点都要更新,中间,会有一些查询 分析:题意倒也不难理解,但是但是不知道怎么建树...于是自能百度,看了kuangb ...

随机推荐

  1. 过滤表名 & 拼接字符串

    /// <summary> /// 分析sql语句中的表名 /// </summary> /// <param name="sql">sql语句 ...

  2. 关于js中的for(var in)遍历属性报错问题

    之前遇到过这个问题,但是没找到问题的所在,将for(var i in  array){} 改成了for(var i ;i<array.length;i++)循环,但是今天又遇到了,mark一下错 ...

  3. 转载:Solr的自动完成实现方式(第二部分:Suggester方式)

    转自:http://www.cnblogs.com/ibook360/archive/2011/11/30/2269077.html 在Solr的自动完成/自动补充实现介绍(第一部分) 中我介绍了怎么 ...

  4. Web开发必知的八种隔离级别

    ACID性质是数据库理论中的奠基石,它定义了一个理论上可靠数据库所必须具备的四个性质:原子性,一致性,隔离性和持久性.虽然这四个性质都很重要,但是隔离性最为灵活.大部分数据库都提供了一些可供选择的隔离 ...

  5. Spring Framework------>version4.3.5----->Reference学习心得----->总结

    1.Spring Framework概述: 有很多可用版本,网址http://projects.spring.io/spring-framework/       2.Spring Framework ...

  6. 第一次将内容添加到azure event hubs

    由于每秒数据吞吐量巨大,需要将实时数据存到event hubs,再由event hubs定时定量保存到document DB. event hubs的介绍详见微软官页:https://azure.mi ...

  7. Entity Framework Code First数据库自动更新

    EF的Code First方式允许你先写Model,再通过Model生成数据库和表. 具体步骤如下: 1.建项目 2.在model文件夹中,添加一个派生自DbContext的类,和一些Model类. ...

  8. selenium2(WebDriver)环境搭建

    1.安装jdk并配置环境变量: jdk安装jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html环境变量 ...

  9. typedef 与指针、多维数组

    1.在typedef中使用指针往往会带来意外的结果.如下: typedef string *pstring; const pstring cstr; 绝大数人刚开始都会认为cstr是一种指针,它指向c ...

  10. tnsnames.ora配置注意(连接新的数据库)

    文件地址D:\app\think\product\11.2.0\instantclient_11_2\network\admin\tnsnames.ora# tnsnames.ora Network ...