SHARE
TWEET

plata(cel putin una din fiec)

uchihamadara3 Oct 14th, 2019 (edited) 80 in 330 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("file.in");
  6. ofstream fout("file.out");
  7.  
  8. /*
  9.     2.a)
  10. */
  11.  
  12. int n, s;
  13. int x[7];
  14. int v[7], c[7];
  15. bool gasit;
  16.  
  17. void afisare()
  18. {
  19.     gasit=true;
  20.     for(int i=1;i<=n;i++)
  21.         fout<<x[i]<<' ';
  22.     fout<<'\n';
  23. }
  24.  
  25. void back(int k, int sp)
  26. {
  27.     if(!gasit)
  28.     for(int i=1;i<=c[k];++i) /// luam cel putin una
  29.     {
  30.         x[k]=i;
  31.         sp+=v[k]*i;
  32.         if(k==n){
  33.             if(sp==s) afisare();
  34.         }
  35.         else back(k+1, sp);
  36.         sp-=v[k]*i;
  37.     }
  38. }
  39.  
  40. int main()
  41. {
  42.     fin>>n>>s;
  43.     for(int i=1;i<=n;++i)
  44.         fin>>v[i];
  45.     for(int i=1;i<=n;++i)
  46.         fin>>c[i];
  47.     back(1, 0);
  48.     return 0;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top