码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2245 Lotto

时间:2014-10-12 15:28:58      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   使用   ar   for   

题目链接:http://poj.org/problem?id=2245

 

思路:

    无重复元素组合组合问题,使用暴力枚举法,注意剪枝条件。

代码:

 

#include <iostream>
using namespace std;

const int MAX_N = 15;
int n, k = 6;
int Set[MAX_N], A[MAX_N];

void Comnination( int deep, int index )
{
    if ( deep == k  )
    {
        int i;

        for ( i = 0; i < k - 1; ++i )
            cout << A[i] << " "; 
        cout << A[i] << endl;
    }
    else
    if ( index == n && deep != k )
        return;
    else
    {
        for ( int i = index; i < n; ++i )
        {
            A[deep] = Set[i];
            Comnination( deep + 1, i + 1 );
        }
    }
}

int main( )
{
    while ( cin >> n )
    {
        if ( n == 0 )
            break;

        for ( int i = 0; i < n; ++i )
            cin >> Set[i];

        Comnination( 0, 0 );
        cout << endl;
    }

    return 0;
}

 

poj 2245 Lotto

标签:style   blog   http   color   io   os   使用   ar   for   

原文地址:http://www.cnblogs.com/tallisHe/p/4020394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!