Advertisement
erfanul007

UVa 10130

Aug 11th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  26. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  27. #define cspf(i) printf("Case %d: ", i)
  28. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  29. #define pb push_back
  30. #define mp make_pair
  31. #define ff first
  32. #define ss second
  33. #define clr(a,x) memset(a,x,sizeof(a));
  34. #define all(v) v.begin(),v.end()
  35. #define rall(v) v.rbegin(),v.rend()
  36. #define read() freopen("input.txt", "r", stdin)
  37. #define write() freopen("output.txt", "w", stdout)
  38. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  39. /// Constants
  40. #define eps 1e-9
  41. #define PI acos(-1.0) // 3.1415926535897932
  42. #define MAX 100000009
  43.  
  44. struct node{
  45. int w,v;
  46. }a[1002];
  47.  
  48. int cnt[1002][1002], n;
  49.  
  50. int dpsolve(int i, int w)
  51. {
  52. if(i>n) return 0;
  53. if(cnt[i][w]!=-1) return cnt[i][w];
  54. int mx1=0,mx2=0;
  55. if(w-a[i].w>=0) mx1 = a[i].v + dpsolve(i+1, w-a[i].w);
  56. mx2 = dpsolve(i+1, w);
  57. return cnt[i][w] = max(mx1, mx2);
  58. }
  59.  
  60. int main()
  61. {
  62. //read();
  63. //write();
  64. int t;
  65. sci(t);
  66. while(t--){
  67. sci(n);
  68. loop(i,1,n){
  69. scii(a[i].v,a[i].w);
  70. }
  71. int g,x,total=0;
  72. sci(g);
  73. clr(cnt,-1);
  74. loop(i,1,g){
  75. sci(x);
  76. total+=dpsolve(1, x);
  77. }
  78. pfi(total);line;
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement