Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- //ifstream cin("test.in");
- //ofstream cout("test.out");
- int n,V[10],C[10],S,X[10],ok=1;
- void afisare()
- {
- for(int i = 1; i <= n; i++)
- cout <<X[i]<<" ";
- cout <<'\n';
- }
- void back(int k,int pp)
- {
- for(int i = 0; i <= C[k]&&ok==1;i++) // 1->cate sunt de tipul k
- {
- X[k]=i;
- pp=pp+V[k]*X[k];//vaxloare *cate am pus
- if(pp <= S)
- if(k==n)
- {
- if(pp==S) afisare(),ok=0;
- }
- else back(k+1,pp);
- pp-=V[k]*X[k];
- }
- }
- int main()
- {
- cin >> n>>S;
- for(int i = 1; i <= n;i++)
- cin >> V[i];
- for(int i = 1; i <= n;i++)
- cin >> C[i];
- back(1,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement