Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int c[1003][10003],gmax,n;
  5. struct obiect{int g,v;}a[1003];
  6. void citire()
  7. {
  8. cin>>n>>gmax;
  9. for (int i=1;i<=n;i++)
  10. {
  11.  
  12. cin>>a[i].g;
  13. cin>>a[i].v;}
  14. }
  15. void PD()
  16. {
  17. for(int i=1;i<=n;i++)
  18. for(int j=1;j<=gmax;j++)
  19. if(a[i].g<=j)
  20. c[i][j]=max(c[i-1][j],c[i-1][j-a[i].g]+a[i].v);
  21. else
  22. c[i][j]=c[i-1][j];
  23. cout<<c[n][gmax];
  24. }
  25.  
  26. int main()
  27. {
  28.  
  29. citire();
  30. PD();
  31.  
  32.  
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement