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. UWP textbox 只能输入数字

    private void Testbox_TextChanged(object sender, TextChangedEventArgs e) {    var textbox = (TextBox) ...

  2. obj.onclick=fnClick与obj.onclick=fnClick()的区别

    先说结论:这段代码浏览器会报错,提示 aDiv[this.index] is undefined 所以正确的写法应该是去掉(),直接写为function fnClick.   不加括号的话,相当于指定 ...

  3. 中文翻译:pjsip教程(一)之PJNATH简介

    在学习pjsip的过程中,发现只是单单的阅读英文官方文档,对于里边概念的理解还是不够透彻,并且苦于pjsip没有发现全一点的中文版本,所以想尽自己所能为建设和谐社会而贡献一份力量,文中定会有所疏漏,希 ...

  4. MFC可编辑的ListCtrl

    近期由于项目的要求,需要一个可以编辑的列表控件,由于MFC提供的列表控件只支持第一行可编辑,无法满足项目需求,故只能自己动手重写一个列表控件.重写列表控件的思想为:当点击列表的某行某列时,在此处创建一 ...

  5. 2、Python djang 框架下的word Excel TXT Image 等文件的下载

    2.python实现文件下载 (1)方法一.直接用a标签的href+数据库中文件地址,即可下载.缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开. ...

  6. go和swift

    你生命中的有些东西终究会失去,比如我住了6年的陈寨,这个聚集了郑州十几万IT民工的地方,说拆就拆了.再比如我玩了3年的坦克英雄,这个带给我太多快乐的游戏,说停就停了. 编程对我而言是种爱好,我上学6年 ...

  7. js 删除数组方法

    今天遇到一个比较脑残的问题 ,在在用js删除数组的时候 delete 数组[下标]的方法删除数组时,该数组的下标变为null,但是数组的长度并没有发生相应的变化 转而使用splice(小标,第N个)删 ...

  8. 精通 Oracle+Python,第 2 部分:处理时间和日期

    从 Python 2.4 版开始,cx_Oracle 自身可以处理 DATE 和 TIMESTAMP 数据类型,将这些列的值映射到 Python 的 datetime 模块的 datetime 对象中 ...

  9. directUI

    MFC界面开发中,习惯了使用控件,亦或者是自绘制控件来美化界面,但操作起来繁琐,还不太美观.DirectUI的出现,对于界面开发,给了我们一个新的选择,目前很多公司使用了该技术对其产品进行了美化,效果 ...

  10. Python核心编程2第五章课后练习

    5-1 整型,讲讲python普通整型与长整型区别 python整形一共有三种:布尔型,长整型和标准整型.普通整型与长整型的区别在于标准整形的取值范围是-2^31到2^31-1,长整型所能表达的数值与 ...