POJ 2245 Lotto dfs

给出最多13个数,从中选出6个数(升序)

给出所有方案(升序输出)

DFS水题

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 10;
const int M = 16;
int ans[N];
int a[M];
int n;
void dfs(int id, int pre){
    if(id == 6) {
        for(int i = 0; i < 6; i++)  printf("%d%c", ans[i], i == 5 ? ‘\n‘ : ‘ ‘);
        return ;
    }
    if(pre == n)    return;

    ans[id] = a[pre + 1];
    dfs(id + 1, pre + 1);
    dfs(id, pre + 1);
}
int main(){
    int i;
    bool newline = false;
    while(scanf("%d", &n) &&n){
        if(newline) printf("\n");
        for(i = 1; i <= n; i++){
            scanf("%d", &a[i]);
        }
        newline = true;

        dfs(0, 0);
    }
}

时间: 2024-08-05 06:49:47

POJ 2245 Lotto dfs的相关文章

周赛 POJ 2245 Lotto

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 the

POJ 2245 Lotto

Lotto 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, a

hdu1342 &amp;&amp; poj 2245 Lotto

Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1755    Accepted Submission(s): 860 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49

Dearboy&#39;s Puzzle (poj 2308 搜索 dfs+bfs)

Language: Default Dearboy's Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1202   Accepted: 208 Description Dearboy is a game lover. Recently, he loves playing the game Lian Lian Kan. This game is played on a board with N*M grids

[POJ 1011]Sticks(DFS剪枝)

Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were original

POJ 题目2245 Lotto(DFS水)

Lotto Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6549   Accepted: 4153 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 chan

POJ 1011 - Sticks DFS+剪枝

POJ 1011 - Sticks 题意:    一把等长的木段被随机砍成 n 条小木条    已知他们各自的长度,问原来这些木段可能的最小长度是多少 分析:    1. 该长度必能被总长整除    2. 从大到小枚举,因为小长度更灵活, 可拼接可不拼接    3. 因为每一跟木条都要用到, 故若轮到其中一根原始木段选它的第一根木条时,若第一根木条若不满足,则显然第一根木条在接下来任何一根原始木段都不会满足,故无解    4. 由于所有棒子已排序,在DFS时,若某根棒子未被选,则跳过其后面所有与

POJ 1564 经典dfs

1.POJ 1564 Sum It Up 2.总结: 题意:在n个数里输出所有相加为t的情况. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define F(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memse

poj 1154 LETTERS dfs入门题

//poj 1154 //sep9 #include <iostream> using namespace std; const int maxR=32; char a[maxR][maxR]; int r,s; int ans=1; int vis[200]; void dfs(int i,int j,int len) { ans=max(ans,len+1); if(i+1<r&&vis[a[i+1][j]]==0){ vis[a[i+1][j]]=1; dfs(i+