Cod sursa(job #1238832)

Utilizator valentinraduValentin Radu valentinradu Data 7 octombrie 2014 20:19:31
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.65 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int n, S, a[101], i, b[7];
int compare(int a, int b)
{
    return a > b;
}

void proc(int k, int Sx, int pos)
{
    for (int i = k + 1; i <= n; i++)
    {
        if ((b[1] != 0 && b[2] != 0 && b[3] != 0 && b[4] != 0 && b[5] != 0 && b[6] != 0)) break;
        if (Sx - a[i] >= 0)
        {
            b[pos] = a[i];
            proc(i - 1, Sx - a[i], pos + 1);
        }
        else
        {
            proc(i, Sx - a[i], pos + 1);
        }
    }
}
int main()
{
    f >> n >> S;
    int Sx = S;
    for (i = 1; i <= n; i++) f >> a[i];
    sort(a + 1, a + n + 1, compare);
    proc(0, S, 1);
    for (i = 1; i <= 6; i++) g << b[i] << " ";
    return 0;
    for (int j = 1; j <= n; j++)
    {
        int x = j;
        S = Sx;
        if (b[1] == 0 || b[2] == 0 || b[3] == 0 || b[4] == 0 || b[5] == 0 || b[6] == 0)
        {
            for (i = 1; i <= 6; i++) b[i] = 0;
            for (int i = 1; i <= 6; i++)
            {
                if (S - a[x] >= 0)
                {
                    S = S - a[x];
                    b[i] = a[x];
                }
                else
                {
                    x++;
                    i--;
                }
            }
            /*if (S != 0)
            {
                g << "-1";
                return 0;
            }*/
        }
        else
        {
            cout << j;
            break;
        }
    }
    for (i = 1; i <= 6; i++) g << b[i] << " ";
    f.close();
    g.close();
    return 0;
}