Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAXN 1005
  4. #define MAXV 1005
  5.  
  6. int T;
  7. int N, V;
  8. int W[MAXN];
  9. int C[MAXN];
  10. int F[MAXV];
  11.  
  12. int get_max(int a, int b) {
  13. return a > b ? a : b;
  14. }
  15.  
  16. int main () {
  17. scanf ("%d", &T);
  18. while (T--) {
  19. scanf ("%d%d", &N, &V);
  20. for (int i=1; i<=N; ++i)
  21. scanf ("%d", W + i);
  22. for (int i=1; i<=N; ++i)
  23. scanf ("%d", C + i);
  24. memset(F, 0, sizeof (F));
  25. for (int i=1; i<=N; ++i)
  26. for (int v=V; v>=C[i]; --v)
  27. F[v] = get_max (F[v], F[v-C[i]] + W[i]);
  28.  
  29. printf("%d\n", F[V]);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement