Advertisement
Guest User

DP

a guest
May 3rd, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. uses math;
  2. const
  3. tak_hingga=-1000000000;
  4.  
  5. var
  6. n,p,q,z,x:longint;
  7. B,D,W: array [1..10000] of longint;
  8. st:string;
  9. function DP(i,j:longint):longint;
  10. begin
  11. if (i=0) and (0<=j) and (j<=P) then DP:=0
  12. else if (1<=i) and (i<=n) and (j<0) then DP:=tak_hingga
  13. else DP:=max( DP(i-1,j), DP(i-1,j-B[i])+ D[i]);
  14. end;
  15.  
  16.  
  17. begin
  18. readln(st);
  19. readln(N,P,Q);
  20. for x:=1 to n do readln(B[x],D[x],W[x]);
  21. z:=DP(n,P);
  22.  
  23. if z<0 then writeln(0)
  24. else writeln(z);
  25. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement