Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int L, n;
- int a[100]; //Vectorul cu repere
- int v[100]; //Vectorul solutiei
- void afis(int k){
- static int nr = 1;
- cout << "\nSolutia #" << nr++ << " : ";
- for(int i = 1; i <= k;i++) cout << v[i] << " ";
- }
- void backt(int lung, int k){
- for (int i=1; i <=n;i++){
- v[k] = a[i];
- lung += a[i];
- if(lung == L) afis(k);
- else if (lung < L) backt(lung,k+1);
- lung -= a[i];
- }
- }
- int main()
- {
- ifstream in("date.txt");
- in >> L >> n;
- for (int i=1;i<=n;i++) in >> a[i];
- backt(0,1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement