Cod sursa(job #2040565)

Utilizator GrandmasterSoucup Bogdan Grandmaster Data 15 octombrie 2017 23:36:54
Problema Loto Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <fstream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
//#include <unordered_map>
#include <iomanip>
#include <time.h>
#include <stdio.h>
#include <bitset>
#include <map>
#include <ctime>
#define MAX 500000000000
//#include <iostream>
//#include <windows.h>
#include <deque>
//#include "PEZai.h"
//#include <Tlhelp32.h>
using namespace std;
//ifstream cin("jocul.in");
//ofstream cout("jocul.out");
ifstream cin("loto.in");
ofstream cout("loto.out");
int n, s, x[105], ok;
map<int, int> tr[8];
vector<int> dp[9];
int main()
{
    cin >> n >> s;
    dp[0].push_back(0);
    tr[0][0] = 1;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        dp[1].push_back(x[i]);
        tr[1][x[i]] = 1;
    }
    for(int i = 2; i <= 6; i++)
    {
        for(int k = 0; k < dp[i - 1].size(); k++)
            for(int j = 0; j < n; j++)
                if(tr[i][dp[i - 1][k] + x[j]] == 0)
                {
                    tr[i][dp[i - 1][k] + x[j]] = 1;
                    dp[i].push_back(dp[i - 1][k] + x[j]);
                }
    }
    for(int i = 6; i >= 1; i--)
    {
        for(int j = 0; j < n; j++)
            if(tr[i - 1][s - x[j]] != 0)
            {
                cout << x[j] << " ";
                s -= x[j];
                ok = 1;
                break;
            }
    }
    if(ok == 0)
        cout << -1;
}