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

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

Source

 
题意:给定一个k个数的升序序列,从中取出6个,按照字典序输出所有组合方式
思路就是dfs了,算是比较简单的dfs,很快就敲出来了。
 
/*
ID: LinKArftc
PROG: poj2245.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ; int num[maxn];
int n;
int ans[]; void dfs(int cnt, int cur) {
if (cnt == ) {
for (int i = ; i <= ; i ++) printf("%d%c", ans[i], i == ? '\n' : ' ');
return ;
}
if (cur > n) return;
for (int i = cur; i <= n; i ++) {
cnt ++;
ans[cnt] = num[i];
dfs(cnt, i + );
cnt --;
}
} int main() { int _t = ;
while (~scanf("%d", &n) && n) {
if (_t > ) printf("\n");
_t ++;
for (int i = ; i <= n; i ++) scanf("%d", &num[i]);
dfs(, );
} return ;
}
 
 

POJ2245 Lotto的更多相关文章

  1. poj 2245 Lotto

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

  2. ZOJ 1089 Lotto

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

  3. hdoj 1342 Lotto【dfs】

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

  4. Lotto(dfs)

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

  5. HDU1342 Lotto 【深搜】

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

  6. Lotto

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

  7. 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 ...

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

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

  9. 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. Python request 简单使用

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  2. Lambda表达式在Kotlin中怎样工作的:setOnClickListener的转换(KAD 18)

    作者:Antonio Leiva 时间:Mar 28, 2017 原文链接:https://antonioleiva.com/lambdas-kotlin-android/ 虽然,我在其它文章讲过一点 ...

  3. 转型、java基础之Java变量命名规范 (转载)

    向上转型:基类引用指向导出类(派生类)的对象(实例)向下转型:导出类的引用指向基类的对象(实例)  重点:向下转型只有将该引用的导出类的向上转型后向下转型,运行时才不会报错 Java是一种区分字母的大 ...

  4. 多版本python import 问题解决方案

    原文http://www.tuicool.com/articles/EnE7nm6 多版本Python共存[支持使用pip安装包] 有时特殊需要会要用到高版本的Python, 但是系统自带的版本又是很 ...

  5. Spring MVC自动为对象注入枚举数据

    一.实现转换工厂,定义转换实现,如下:     package com.mafwo; import org.springframework.core.convert.converter.Convert ...

  6. 官方文档 恢复备份指南五 Configuring the RMAN Environment

    本章内容: Configuring the Environment for RMAN Backups    配置RMAN环境 Configuring RMAN to Make Backups to a ...

  7. c语言实现带LRU机制的哈希表

    #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  8. PAT L2-019 悄悄关注

    https://pintia.cn/problem-sets/994805046380707840/problems/994805059731177472 新浪微博上有个“悄悄关注”,一个用户悄悄关注 ...

  9. Codeforces Round #391 div1 757F (Dominator Tree)

    首先先膜杜教orz 这里简单说一下支配树的概念 支配树是对一个有向图来讲的 规定一个起点s,如果s到v的路径上必须经过某些点u,那么离s最近的点u就是v的支配点 在树上的关系就是,v的父亲是u. 一般 ...

  10. HDU 6153 A Secret(扩展KMP模板题)

    A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others) Total ...