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 ...
随机推荐
- invoke
在用.NET Framework框架的WinForm构建GUI程序界面时,如果要在控件的事件响应函数中改变控件的状态,例如:某个按钮上的文本原先叫“打开”,单击之后按钮上的文本显示“关闭”,初学者往往 ...
- 循序渐进Python3(十一) --4-- web之jQuery
jQuery jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的 ...
- 有关Select option 元素
动态添加option元素以及option元素被选中方法: function getType() { ); shadowCoverTipAdd("加载中,请稍候.."); $.aja ...
- web前端安全 XSS跨站脚本 CSRF跨站请求伪造 SQL注入
web安全,从前端做起,总结下web前端安全的几种技术: 1,XSS XSS的全称是Cross Site Scripting,意思是跨站脚本,XSS的原理也就是往HTML中注入脚本,HTML指定了脚本 ...
- 我的 C++ style
int g_tennis; // not use as possible int make_world() { ; return size; } ; enum Color { RED, GREEN } ...
- VoLTE 注册流程
1.开关按钮位置: 设置--> 更多--> 移动网络--> 增强型4G LTE模式 2.该设置开关使用了SwitchPreference控件,addEnhanced4GLteSw ...
- RPC学习--C#使用Thrift简介,C#客户端和Java服务端相互交互
本文主要介绍两部分内容: C#中使用Thrift简介 用Java创建一个服务端,用C#创建一个客户端通过thrift与其交互. 用纯C#实现Client和Server C#服务端,Java客户端 其中 ...
- python学习之——splinter使用
开始学习使用splinter工具了,目前是摸索中,先熟悉splinter工具的使用方法~~ 实现功能: 打开firefox浏览器->www.baidu.com->输入关键词 python, ...
- Guava学习笔记:Google Guava 类库简介
http://www.cnblogs.com/peida/tag/Guava/ Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, cachin ...
- MVC5+EF6 简易版CMS(非接口) 第四章:使用业务层方法,以及关联表解决方案
目录 简易版CMS后台管理系统开发流程 MVC5+EF6 简易版CMS(非接口) 第一章:新建项目 MVC5+EF6 简易版CMS(非接口) 第二章:建数据模型 MVC5+EF6 简易版CMS(非接口 ...