Cod sursa(job #597268)

Utilizator ion_calimanUAIC Ion Caliman ion_caliman Data 21 iunie 2011 16:46:03
Problema Loto Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int n, a[100],s,v[6];
ifstream f("loto.in");
ofstream g("loto.out");

void afis()
{
    for (int i=0; i<6; i++)
        g << v[i] << ' ';
    exit(0);
}

void rec(int poz, int sum)
{
    if ((sum==s)&&(poz==6)) afis();
    else
    if (poz<6)
    {
        for (int i=0; i<n; i++)
        if (sum+a[i]<=s)
        {
            v[poz]=a[i];
            rec(poz+1,sum+a[i]);
        }
    }
}

int main()
{
    int i;
    f >> n >> s;
    for (i=0; i<n; i++)
        f >> a[i];
    sort(a, a+n);
    reverse(a, a+n);
    rec(0,0);
    g << -1;
    return 0;
}