Lotto
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6605   Accepted: 4185

Description

In the German Lotto you have 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 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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[],b[],n; void dfs(int num,int p)
{
int i;
if(p>n)
return ;
if(num>=)
{
for(i=;i<;i++)
printf("%d ",b[i]);
printf("%d\n",b[]);
return ;
}
b[num]=a[p];
dfs(num+,p+);
dfs(num,p+);
return;
}
int main()
{
int i,flag=;
while(scanf("%d",&n),n)
{
if(flag)
printf("\n");
flag=;
for(i=;i<n;i++)
scanf("%d",&a[i]); dfs(,);
} }
												

Lotto--poj2245的更多相关文章

  1. POJ2245 Lotto

    Lotto Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6634   Accepted: 4201 Description ...

  2. poj 2245 Lotto

    Lotto Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6806   Accepted: 4298 Description ...

  3. ZOJ 1089 Lotto

    原题链接 题目大意:有一种抽奖游戏乐透(Lotto),规则是从1到49这49个自然数中随机抽取6个数.现在有一种简化版的游戏,先在49个数里面选出k(6<k<13)个数,然后再从这k个数里 ...

  4. hdoj 1342 Lotto【dfs】

    Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. Lotto(dfs)

    Lotto Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submis ...

  6. HDU1342 Lotto 【深搜】

    Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  7. Lotto

    Lotto Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submiss ...

  8. ZOJ2402 Lenny's Lucky Lotto List 简单DP

    Lenny's Lucky Lotto Lists Time Limit: 2 Seconds      Memory Limit:65536 KB Lenny likes to play the g ...

  9. 隐马尔科夫模型研究 stock 以及 lotto

    说明 本文参考了这里 由于数据是连续的,因此使用了高斯隐马尔科夫模型:gaussianHMM 一.stock代码 import tushare as ts import pandas as pd im ...

  10. ZOJ2402 Lenny's Lucky Lotto List 简单DP

    Lenny's Lucky Lotto Lists Time Limit: 2 Seconds      Memory Limit:65536 KB Lenny likes to play the g ...

随机推荐

  1. new String(byte[])和byte[]toString() 的区别

    byte[]字节数组的toString()获得的字符串和使用new String(byte[])构造一个新的字符串,这两个字符串是不一样的.Java对象都继承于Object,Object中提供了toS ...

  2. 2015年阿里巴巴蚂蚁金服校招JAVA研发工程师内推电话面试

    没想到阿里校招如此之早,虽然早已进入复习备战状态,但还是感觉有些措手不及...找了个在蚂蚁金服做HR的同学帮忙了内推,然后在最近的几天匆匆忙忙地复习JAVA(之前都把精力放在了数据结构.算法等基础上了 ...

  3. Java开发者工具

    From:http://www.csdn.net/article/2015-03-26/2824317 1. Notepad++ Notepad++是用于编辑xml.脚本以及记笔记的最佳工具.这个工具 ...

  4. 关于set和map的用法

    1.set 定义:每个元素最多只出现一次,并且默认的是从小到大排序. set 遍历: 题目http://www.cnblogs.com/ZP-Better/p/4700218.html for(set ...

  5. 各硬件装置在 Linux 中的文件名(笔记)

    各硬件装置在 Linux 中的文件名

  6. 为什么Myeclipse 提示Project 'bankmanager' is missing required library,myeclipse项目上红叉 但内部红叉

    应该是正在使用的项目是从网上下的或者别人那里直接拷贝导致的,解决办法: 下一个mysql-connector-java-5.1.22-bin.jar或者是最新版,最好放项目目录里 右键点项目,Buil ...

  7. 通过项目逐步深入了解Mybatis<四>

    延迟加载 什么是延迟加载? resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能. ...

  8. ubuntu 14.04 chromium 设备adobe flash player(亲测可行)

    首先,根据浏览器提示下载Adobe Flash Player 插入 install_flash_player_11_linux.x86_64.tar.gz;然后使用sudo tar -xzvf ins ...

  9. 购买DigtalOcean VPS 以及 连接Linux

    1.DigtalOcean简介 digitalocean是一家成立于2012年的总部设置在纽约的云主机商家,眼下在荷兰的阿姆斯特丹(AMS1.AMS2).美国的纽约(NYC1.NYC2)和旧金山(SF ...

  10. Hadoop 安装(1) CENTOS 安装与配置

    配置虚拟机,名字 Hadoop_Slave4,内存为1024MB,15GB. 进入安装centos. 配置Hostname: Slave4.Hadoop 配置网络,设置静态IP:192.168.1.2 ...