Tuesday, 5 May 2015

UVA 441 Lotto (POJ 2245, ZOJ 1089, FZU 1047, HDU 1342, SCU 1027)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / hackerrank / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100010

int arr[15], now[7], n;
bool vis[15];

void backTrack(int sz, int pos)
{
    if(sz==6)
    {
        for(int i=0;i<5;i++)
            cout<<now[i]<<" ";
        cout<<now[5]<<"\n";
        return;
    }
    for(int i=pos;i<n;i++)
        if(!vis[i])
        {
            vis[i]=true;
            now[sz]=arr[i];
            backTrack(sz+1, i+1);
            vis[i]=false;
        }
    return;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=0;
    string s;
    while(cin>>n && n)
    {
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(kk) cout<<"\n";
        backTrack(0, 0);

        kk++;
    }
return 0;
}

No comments:

Post a Comment