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飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...
随机推荐
- windows 远程连接linux服务器
百度搜索“SSH Secure Shell Client” 并下载 2 点击Profiles选择add profiles 并添加profils名称 3 点击Profiles 填写远程linux的ip ...
- openssl移植
一.下载openssl 1.下载网址http://www.openssl.org/source/ 2.下载版本openssl-1.0.0q.tar.gz 二.编译openssl为静态库(X86 lin ...
- 【工具篇】notepad++
一直都是使用notepad++来写程序,感觉比UE好用多了,没有UE那么重.前段时间网上还做了一个调查,notepad++在国外使用排行还是非常高的,在国内也是很流行.以下记录一些比较实用的技巧. 一 ...
- [lua]再版jobSchedule与脚本描述范型
首先贴上代码 -- CPM:关键路径法(Critical Path Method) jobSchedule = { todos = { -- todo list ... ["finale&q ...
- WPF提示框效果
WPF提示框效果 1,新建WPF应用程序 2,添加用户控件Message 3,在Message中编写如下代码 <Border x:Name="border" BorderTh ...
- Python【第一篇】基础介绍
一.本节主要内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc文件 数据类型初识 数据运算 表达式if ...else语 ...
- void (*f(int, void (*)(int)))(int) 函数解析 转
今天与几个同学看到了一个函数指针定义: void (*f(int, void (*)(int)))(int) 以前在C trap pit fails里面见过,但是文章里面介绍的很详细,但是往往使初学者 ...
- 一种轻量的openresty路由设计
在使用openresty开发接口的过程会发现一个问题,那就是接口的地址问题怎么解决,最好一个接口地址对应一个lua文件,也可以在nginx.conf 配置中使用content_by_lua 来编写接口 ...
- SQL脚本小笔记
--表添加字段.说明--- --脚本 alter table 表名 ADD 字段名 FLOAT(类型) NOT NULL Default 0(默认值) EXECUTE sp_addextendedpr ...
- 单元测试unit test,集成测试integration test和功能测试functional test的区别
以下内容转自 https://codeutopia.net/blog/2015/04/11/what-are-unit-testing-integration-testing-and-function ...