Lotto

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

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
 
做完搜索真的感觉自己的智商太不够用了....
#include<stdio.h>
#include<string.h>
int a[50];
int b[10];
int t;
void dfs(int x,int y)
{
int i;
if(x==7)
{
for(i=1;i<=6;i++)
{
if(i==1)
printf("%d",b[i]);
else
printf(" %d",b[i]);
}
printf("\n");
return ;
}
if(y>t) return ;
b[x]=a[y];
x++;
dfs(x,y+1);
x--;
dfs(x,y+1);
}
int main()
{
int n,m,j,i;
n=0;
while(scanf("%d",&t),t)
{
if(n)
printf("\n");
for(i=1;i<=t;i++)
scanf("%d",&a[i]);
dfs(1,1);
n++;
}
return 0;
}

  

#include<stdio.h>
#include<string.h>
int n,m;
int a[30],b[30];
void dfs(int cur,int pos)
{
int i,j;
if(pos==7)
{
for(i=1;i<7;i++)
{
if(i==1) printf("%d",b[i]);
else printf(" %d",b[i]);
}
printf("\n");
return ;
}
if(cur>n) return ;
b[pos]=a[cur];//将a数组的值给b数组
dfs(cur+1,pos+1);//a数组和b数组同时自身加1移向下一位
dfs(cur+1,pos);//如果上边搜索失败回溯回来则令b数组从后向前改变值
}
int main()
{
int i,j;
int t=0;
while(scanf("%d",&n),n)
{
if(t)
printf("\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
dfs(1,1);
t++;
}
return 0;
}

  

hdoj 1342 Lotto【dfs】的更多相关文章

  1. HDOJ.1342 Lotto (DFS)

    Lotto [从零开始DFS(0)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of ...

  2. hdoj 1455 Sticks 【dfs】

    题意:找最短的木棍可以组成的长度, hdoj  1518 的加强版 代码: #include <stdio.h> #include <string.h> #include &l ...

  3. hdoj 1518 Square 【dfs】

    题意:给出n个(不同长度的)棍子,问能不能将他们构成一个正方形. 策略:深搜. hdoj 1455的简化版 代码: #include <stdio.h> #include <stri ...

  4. hdoj - 1342 Lotto

    Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,... ...

  5. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  6. 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】

    目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...

  7. Kattis - glitchbot 【DFS】

    Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...

  8. HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))

    度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. 【dfs】P1331 海战

    题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...

随机推荐

  1. 冒泡排序--c#

    //冒泡排序 Console.WriteLine("请输入一个程序的数值"); int[] array = { 111, 2, 5, 32, 321 }; int temp = 0 ...

  2. asp.net web api内部培训资料

    最近在公司进行了一次asp.net web api的分享吧,不算是培训. 可能大家有些人对Web API的推出目的还不是很了解,可以看看微软官方的定义,其实是为了提供一个好的REST Service方 ...

  3. js闭包简要分析

    相信大多数接触过js编程的程序员或多或少都对js中的闭包了解一些吧,所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.闭包是 EC ...

  4. 创业 CEO:如何选择投资人

    欢迎来到「创业 CEO」系列,在这个系列中,我们讨论一个创业者如何教会自己成为一位伟大的 CEO,因为历史上最伟大的创业公司,往往都是由这样的人在领导. AppWorks 成立至今,总共参与投资了 2 ...

  5. 24种设计模式--门面模式【Facade Pattern】

    大家都写过纸质的信件吧,比如给女朋友写情书什么的,写信的过程大家都还记得吧,先写信的内容,然后写信封,把信放到信封中,封好,投递到信箱中进行邮递,这个过程还是比较简单的,虽然简单,这四个步骤都是要跑的 ...

  6. 【elasticsearch】(1)centos7 使用yum安装elasticsearch 2.X

    前言 elasticsearch(下面称为ES)是一个基于Lucene的搜索服务器(By 百度百科:查看).所以他需要java的环境即jdk,这里提供懒人一键安装方式 # yum install ja ...

  7. 配置并学习微信JS-SDK(2)—图片接口

    测试地址:http://www.qq210.com/shoutu/android 检查图像接口 选择本地或拍照的图片 上传选择的图片 预览上传的图片 //1.检查图像接口 document.query ...

  8. 一张图看懂DNS域名解析全过程

    DNS域名解析是互联网上非常重要的一项服务,上网冲浪(还有人在用这个词吗?)伴随着大量DNS服务来支撑,而对于网站运营来说,DNS域名解析的稳定可靠,意味着更多用户的喜欢,更好的SEO效果和更大的访问 ...

  9. PAT (Basic Level) 1004. 成绩排名 (20)

    读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第2个学生 ...

  10. bzoj 3594: [Scoi2014]方伯伯的玉米田 dp树状数组优化

    3594: [Scoi2014]方伯伯的玉米田 Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 314  Solved: 132[Submit][Sta ...