Pagini recente » Cod sursa (job #1388198) | Cod sursa (job #1419219) | Cod sursa (job #2728403) | Cod sursa (job #1228654) | Cod sursa (job #3128595)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
bool backtracking(int N, int S, int pas, int suma_curenta, vector<int> &numere, vector<int> &combinatie) {
if (pas == 6) {
if (suma_curenta == S) {
return true;
}
return false;
}
for (int i = 0; i < N; ++i) {
combinatie[pas] = numere[i];
if (backtracking(N, S, pas + 1, suma_curenta + numere[i], numere, combinatie)) {
return true;
}
}
return false;
}
int main() {
int N, S;
ifstream fin("loto.in");
ofstream fout("loto.out");
fin >> N >> S;
vector<int> numere(N);
for (int i = 0; i < N; ++i) {
fin >> numere[i];
}
vector<int> combinatie(6);
if (backtracking(N, S, 0, 0, numere, combinatie)) {
for (int i = 0; i < 6; ++i) {
fout << combinatie[i] << ' ';
}
} else {
fout << -1;
}
fin.close();
fout.close();
return 0;
}