Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int st[100], m[100]={ 0, 4, 5, 3 };
- int n, s, c;
- struct feluri
- {
- char nume[256];
- int calorii;
- double pret;
- };
- struct mancaruri
- {
- feluri fel[100];
- }vector[100];
- void citeste()
- {
- ifstream fin("mancare.in");
- fin >> s >> c;
- for(int i=1; i<=n; i++)
- for(int j=1; j<=m[i]; j++)
- {
- fin >> vector[i].fel[j].nume;
- fin >> vector[i].fel[j].calorii;
- fin >> vector[i].fel[j].pret;
- }
- fin.close();
- }
- void init(int k)
- {
- st[k] = 0;
- }
- int succesor(int k)
- {
- if(st[k] < m[k])
- {
- st[k] = st[k] + 1;
- return 1;
- }
- else
- return 0;
- }
- int valid(int k)
- {
- return 1;
- }
- int solutie(int k)
- {
- return n == k;
- }
- void tipar(int k)
- {
- int sumaC = 0;
- int sumaP = 0;
- for(int i = 1; i <= n; i++)
- {
- sumaP += vector[i].fel[st[i]].pret;
- sumaC += vector[i].fel[st[i]].calorii;
- }
- if(sumaC < c && sumaP < s)
- {
- for(int i=1; i<=n; i++)
- cout << vector[i].fel[st[i]].nume << " ";
- cout << " | " << sumaP << " | " << sumaC;
- cout << '\n';
- }
- }
- void bkt(int k)
- {
- init(k);
- while(succesor(k))
- {
- if(valid(k))
- {
- if(solutie(k))
- {
- tipar(k);
- }
- else
- bkt(k+1);
- }
- }
- }
- int main()
- {
- n = 3;
- citeste();
- bkt(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement