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 ...
随机推荐
- 企业级监控平台开发之nagios二次开发(七)
背景: A公司里有很多服务器(>3000台),每台服务器都有不同的用途,如DB Server.WEB Server.ESXI等,每个组使用其中的一批,每个组可能有多个服务器管理员.现在问题出来了 ...
- hive中分号问题
分号是sql的结束符,在hql中亦如此,但是hive对分号的识别没有那么智能,如下: select concat(';','aa') from lhc limit 1; FAILED: Parse E ...
- #define 小知识
#define N 15 #define M 2+N #define W 2*M 问3*W的结果是多少? 结果为27: 知识点:define只能进行非常简单的运算,简单来说就是仅仅是将自身的值代入,而 ...
- JS中简单原型的使用
- thinkphp 数据访问
<?php namespace Admin\Controller; use Think\Controller; class MainController extends Controller { ...
- webView 点击页面跳转到浏览器
@interface ForumDetailViewController ()<UIWebViewDelegate> { NSUInteger _clickedNumber; } @end ...
- (引用)Python 生成随机数小结
转载:http://blog.csdn.net/shuaijiasanshao/article/details/51339438
- Linux 中 Vi 编辑器的简单操作
Linux 中 Vi 编辑器的简单操作 Vi 编辑器一共有3种模式:命名模式(默认),尾行模式,编辑模式.3种模式彼此需要切换. 一.进入 Vi 编辑器的的命令 vi filename //打开或新 ...
- Android学习---数据库的增删改查(sqlite CRUD)
上一篇文章介绍了sqlite数据库的创建,以及数据的访问,本文将主要介绍数据库的增删改查. 下面直接看代码: MyDBHelper.java(创建数据库,添加一列phone) package com. ...
- 如何在xml文件中加注释或取消注释
1)加注释:Ctrl+Shift+/ 2)取消注释:Ctrl+Shift+\ 本文欢迎转载,但请注明作者与出处: 作者:Sophia 出处:http://www.cnblogs.com/Sophia- ...