Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef unsigned long long int ull;
- typedef long long int ll;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef vector<vi> vvi;
- typedef pair<int,int > pii;
- typedef vector< pii > vpii;
- typedef set<int> sti;
- #define sc scanf
- #define pf printf
- #define sci(n) scanf("%d",&n)
- #define scii(n,m) scanf("%d %d",&n,&m)
- #define scl(n) scanf("%lld",&n)
- #define scd(n) scanf("%lf",&n)
- #define scs(s) scanf("%s",s)
- #define pfi(n) printf("%d",n)
- #define pfl(n) printf("%lld",n)
- #define pff(n) cout<<n
- #define line printf("\n")
- #define spc printf(" ")
- #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
- #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
- #define cspf(i) printf("Case %d: ", i)
- #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define clr(a,x) memset(a,x,sizeof(a));
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
- /// Constants
- #define eps 1e-9
- #define PI acos(-1.0) // 3.1415926535897932
- #define MAX 100000009
- struct node{
- int w,v;
- }a[1002];
- int cnt[1002][1002], n;
- int dpsolve(int i, int w)
- {
- if(i>n) return 0;
- if(cnt[i][w]!=-1) return cnt[i][w];
- int mx1=0,mx2=0;
- if(w-a[i].w>=0) mx1 = a[i].v + dpsolve(i+1, w-a[i].w);
- mx2 = dpsolve(i+1, w);
- return cnt[i][w] = max(mx1, mx2);
- }
- int main()
- {
- //read();
- //write();
- int t;
- sci(t);
- while(t--){
- sci(n);
- loop(i,1,n){
- scii(a[i].v,a[i].w);
- }
- int g,x,total=0;
- sci(g);
- clr(cnt,-1);
- loop(i,1,g){
- sci(x);
- total+=dpsolve(1, x);
- }
- pfi(total);line;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement