hdoj 1342 Lotto【dfs】
Lotto
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1736 Accepted Submission(s):
854
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.
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.
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<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】的更多相关文章
- HDOJ.1342 Lotto (DFS)
Lotto [从零开始DFS(0)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of ...
- hdoj 1455 Sticks 【dfs】
题意:找最短的木棍可以组成的长度, hdoj 1518 的加强版 代码: #include <stdio.h> #include <string.h> #include &l ...
- hdoj 1518 Square 【dfs】
题意:给出n个(不同长度的)棍子,问能不能将他们构成一个正方形. 策略:深搜. hdoj 1455的简化版 代码: #include <stdio.h> #include <stri ...
- hdoj - 1342 Lotto
Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,... ...
- HDOJ 1501 Zipper 【DP】【DFS+剪枝】
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- Kattis - glitchbot 【DFS】
Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...
- HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 【dfs】P1331 海战
题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...
随机推荐
- iOS支付总结
内容大纲: 一.常见的支付方案简介 二.第三方支付SDK 三.苹果官方支付方案 四.Web支付方案 正文: 一.常见的支付方案简介 在微信支付中 微信支付的网址是: https://pay.weixi ...
- java动态绑定的情况分析
java是面向对象的语言,java中多态的一种情况是动态绑定.所谓的动态绑定,分两种情况:当调用类方法的时候,java虚拟机会基于对象的引用类型来选择执行方法.当java调用一个实例方法的时候,他会根 ...
- Lucene5.x 中文 同义词
查询好好多资料,英文同义词好好的,中文就不行,多谢网友支持,拼接了好多代码,然后修改了一些,不足之处,多谢指正. 直接上代码吧,在代码中了解怎么分词的最好 1,创建分词引擎 public interf ...
- Codevs 1337 银行里的迷宫
1337 银行里的迷宫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 传送门 题目描述 Description 楚楚每一次都在你的帮助下过了一关又一关(比如他开 ...
- C++单元测试2
这里再对上一篇<C++单元测试>进行技巧补充. 我们知道对动态链接库(lib和dll)的测试是比较简单的,我这里主要对需要注意的地方说明一下. 1.建议单独创建单元测试解决方案(不是创建项 ...
- 接触.net5年了,感觉自己的知识面很狭隘。
08年毕业找工作期间开始接触网页开发,由于在学校了混了4年时间,我只能从html标记语言开始学习,后来应聘到一个网站建设公司,开始学习ps.Dreamweaver和asp.由于基础薄弱,一个月后离开了 ...
- iphone5手机端内容超出iphone6没问题且超出内容为http://.....网址
- 判断IE浏览器用IE条件表达式
<!--[if IE]> <script type="text/javascript"> alert("ie") </script ...
- ES5中数组新增的方法说明
一.前言-索引 ES5中新增的不少东西,了解之对我们写JavaScript会有不少帮助,比如数组这块,我们可能就不需要去有板有眼地for循环了. ES5中新增了写数组方法,如forEach (js v ...
- about Red_Hat_Enterprise_Linux_7
systemd systemd 是 Linux 的系统和服务管理程序,替换了 Red Hat Enterprise Linux 之前的发行本中使用的 SysV.systemd 与 SysV 和 Lin ...