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. vs2010 “发生生成错误,运行上次的成功运行的程序”怎么改回不运行。

    当程序出现错误时,会出现下面对话框: 如果选择"是",并且勾选了"不再显示此对话框",对你以后的操作时非常麻烦的. 许多同学想再次调出次窗口,不知道怎么操作,操 ...

  2. Linux 消息队列编程

    消息队列.信号量以及共享内存被称作 XSI IPC,它们均来自system V的IPC功能,因此具有许多共性. 键和标识符: 内核中的每一种IPC结构(比如信号量.消息队列.共享内存)都用一个非负整数 ...

  3. winform程序开机自动启动代码

    几天前头儿要我实现程序能开机自动启动,搞好了,整理起来写下来. private void checkBox1_CheckedChanged(object sender, EventArgs e) { ...

  4. 帝国cms7.0修改“信息提示”框

    具体修改查看e/message/index.php文件 上传一张合适用的图 <table width="600" height="224" border= ...

  5. Android Capability 细粒度的权限控制

    1. 传统的UID/GID,权限颗粒度太大 2. Capability: 细粒度的权限控制 3. 进程的Capability 4. 文件的Capability 5. 进程的Capability Bou ...

  6. User Commands

    archive Creates a hadoop archive[v.存档; n.档案文件; 档案室; ]. More information can be found at Hadoop Archi ...

  7. Django 1

    Django 1.10文档中文版Part1 本文是博主翻译的Django1.10版本官方文档的第一部分,如时间充裕,争取一直翻译下去,经验不足,或有错漏,敬请指正.另外对于公开文档进行翻译的版权问题不 ...

  8. BZOJ 3994 约数个数和

    Description 设\(d(x)\)为\(x\)的约数个数,给定\(N,M\),求\[\sum_{i=1}^{N}\sum_{j=1}^{M}d(ij)\]. Input 输入文件包含多组测试数 ...

  9. Map迭代器

            今天用到了,发现不会,随手谷歌之,整理如下. //Map是接口,刚才在那new Map,汗颜 Map<Character,Integer> mm = new HashMap ...

  10. Java语言基础(一) 标识符

    Java标识符的问题: ①不可以以数字开头 int 123number = 0; //错误 ②可以使用任意的货币符号(¥和$等等)中文也可以  int $i = 0; //正确 int ¥i = 1; ...