hdoj--1342--Lotto(dfs)
Lotto
Total Submission(s): 1887 Accepted Submission(s): 919
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.
specifying the set S, will follow in ascending order. Input will be terminated by a value of zero (0) for k.
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.
7 1 2 3 4 5 6 7
8 1 2 3 5 8 13 21 34
0
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>
#include<string.h>
#include<algorithm>
using namespace std;
int n,num[10010],a[10010],vis[10010];
void dfs(int p,int d)
{
if(d==6)
{
for(int i=0;i<=5;i++)
{
if(i)
printf(" ");
printf("%d",a[i]);
}
printf("\n");
return ;
}
if(p>=n) return ;
for(int i=p;i<n;i++)
{
if(!vis[i])
{
vis[i]=1;
a[d]=num[i];
dfs(i+1,d+1);
vis[i]=0;
}
}
}
int main()
{
int flog=0;
while(scanf("%d",&n),n)
{
if(flog) printf("\n");
flog=1;
memset(num,0,sizeof(num));
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
dfs(0,0);
}
return 0;
}
hdoj--1342--Lotto(dfs)的更多相关文章
- HDOJ.1342 Lotto (DFS)
Lotto [从零开始DFS(0)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of ...
- hdoj - 1342 Lotto
Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,... ...
- hdoj 1342 Lotto【dfs】
Lotto Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1342(DFS)
Lotto Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDOJ(HDU) 2212 DFS(阶乘相关、)
Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...
- HDOJ Sudoku Killer(dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1426 思路分析:该问题为数独问题,明显解是唯一的,所有采用dfs搜索效果更好: 在搜索时,可以通过3个 ...
- poj 2245 Lotto(dfs)
题目链接:http://poj.org/problem?id=2245 思路分析:无重复元素组合组合问题,使用暴力枚举法,注意剪枝条件. 代码如下: #include <iostream> ...
- HDOJ(HDU).2266 How Many Equations Can You Find (DFS)
HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDOJ(HDU).1258 Sum It Up (DFS)
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...
随机推荐
- ElementUi rules表单验证
ElementUi 表单验证 工作中常用到的JS验证 可以在pattern中书写正则,并且配合elementUI进行表单验证. pattern 属性规定用于验证输入字段的模式.模式指的是正则表达式. ...
- Unity 制作安装程序和卸载程序
1.最简单的方式通过winrar制作 但是做出来的页面好low的感觉 参考链接:https://www.cnblogs.com/fetty/p/5185913.html 2.通过inno制作安装程序: ...
- MooseFS源代码分析(二)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- 重写MPAndroidChart显示标记
MPAndroidChart是实现图表功能的优秀控件, 能够完毕大多数绘制需求. 对于改动第三方库而言, 优秀的架构是继承开发, 而不是把源代码拆分出去. MP在显示标记控件(MarkView)时, ...
- 由动态库文件dll生成lib库文件
本文基于OpenBlas的编译和安装.来说明怎样从一个dll文件生成lib库文件. 參考OpenBlas的说明"Howto generate import library for MingW ...
- java中多线程知识
参考:http://www.cnblogs.com/wxd0108/p/5479442. 引 如果对什么是线程.什么是进程仍存有疑惑,请先Google之,因为这两个概念不在本文的范围之内. 用多线程只 ...
- 51nod-1189: 阶乘分数
[传送门:51nod-1189] 简要题意: 给出一个数n,求出有多少个正整数x,y(0<x<=y)满足$1/n!=1/x+1/y$ 题解: 一开始还以为不可做 结果推一下柿子就会了 $1 ...
- Java中泛型的各种使用
Java中的泛型的使用: 1.普通的泛型使用 在使用类的时候后面的<>中的类型就是我们确定的类型. public class MyClass1<T> {//此处定义的泛型是T ...
- android页面布局(listview填充中间)
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...
- 洛谷P4180 [Beijing2010组队]次小生成树Tree
题目描述 小C最近学了很多最小生成树的算法,Prim算法.Kurskal算法.消圈算法等等.正当小C洋洋得意之时,小P又来泼小C冷水了.小P说,让小C求出一个无向图的次小生成树,而且这个次小生成树还得 ...