Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int algdynamiczny(int n,int maxrozmiar,vector<int> &wagi,vector<int> &wartosci){
- vector<vector<int> >v(n+1);
- for (int i=0;i<=n;i++) v[i].resize(maxrozmiar+1,0);
- for(int i=1;i<=n;i++){
- for(int k=1;k<=maxrozmiar;k++){
- if(k>=wagi[i-1] && v[i-1][k]<v[i-1][k-wagi[i-1]] + wartosci[i-1]{
- v[i][k]=v[i-1][k-wagi[i-1]]+wartosci[i-1];
- }else{
- v[i][k]=v[i-1][k];
- }
- }
- }
- return v[n][maxrozmiar];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement