hdu 1342(DFS)
Lotto
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2933 Accepted Submission(s): 1386
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 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.
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<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)的更多相关文章
- F - JDG HDU - 2112 (最短路)&& E - IGNB HDU - 1242 (dfs)
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬 ...
- F - Auxiliary Set HDU - 5927 (dfs判断lca)
题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...
- hdu - 1072(dfs剪枝或bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 思路:深搜每一个节点,并且进行剪枝,记录每一步上一次的s1,s2:如果之前走过的时间小于这一次, ...
- HDU——2647Reward(DFS或差分约束)
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- P - Sudoku Killer HDU - 1426(dfs + map统计数据)
P - Sudoku Killer HDU - 1426 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为 ...
- hdu 1142(DFS+dijkstra)
#include<iostream> #include<cstdio> #include<cmath> #include<map> #include&l ...
- hdu 1015(DFS)
Safecracker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1181(DFS)变 形 课
变形课 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submis ...
- J - Assign the task - hdu 3974(DFS建树+简单线段树)
题意:给一些节点简单额对应关系,可以组成一个树,如果树的某一个节点更新那么他的所有子节点都要更新,中间,会有一些查询 分析:题意倒也不难理解,但是但是不知道怎么建树...于是自能百度,看了kuangb ...
随机推荐
- 第五章 征服数据库(Spring对DB的使用)——开发持久层
本章内容: 定义Spring对数据库访问的支持 配置数据库资源 使用Spring的JDBC模板 在几乎所有的企业级应用中,都需要构建数据持久层.现在意义上的数据持久层是指把对象或者数据保存到数据库中, ...
- 传输层(2)-TCP连接的建立和终止、TIME_WAIT状态
1.TCP连接的建立和终止 1)三路握手 客户端发送一个SYN(同步)分解,告诉服务器客户将在连接中发送的数据的初始序列号. 服务器发送确认客户的SYN(ACK),同时自己也得发送一个SYN分节,它含 ...
- lua创建文件和文件夹
创建文件夹: os.execute('mkdir xx') 创建文件: f = assert(io.open('a.tmp','w')) f:write('test') f:close()
- 学习C:打印输入中单词长度的水平方向直方图
#include <stdio.h>#define IN 1#define OUT 0#define MAXWL 16 main() { /*打印输入单词长度的水平直方图*/ int c, ...
- Centos apache + mysql + usvn 配置svn 服务器
1.遇到问题 提交异常:'svn/!svn/me'path not found http://www.myexception.cn/cvs-svn/1262826.html 更改http.conf 配 ...
- [转载] Android动态加载Dex机制解析
本文转载自: http://blog.csdn.net/wy353208214/article/details/50859422 1.什么是类加载器? 类加载器(class loader)是 Java ...
- spring的事物实现
Spring的事物主要有三个接口 PlatformTransactionManager. 根据TransactionDefinition配置的事物信息创建事物 TransactionDefinitio ...
- Git 查看某个版本修改了哪些文件
. . . . . 查看某个版本提交了哪些文件,其实就是查看该版本与其上一个版本之间的差异,所以通过 git diff 命令来取得结果,并且对比的是要查看的版本与它的上一个版本的 commit 号. ...
- 串口控RGB三色灯
本文由博主原创,如有不对之处请指明,转载请说明出处. /********************************* 代码功能:串口控RGB三色灯 使用函数: Serial.flush(); / ...
- http2协议翻译(转)
超文本传输协议版本 2 IETF HTTP2草案(draft-ietf-httpbis-http2-13) 摘要 本规范描述了一种优化的超文本传输协议(HTTP).HTTP/2通过引进报头字段压缩以及 ...