hdu2602-Bone Collector(01背包模版题)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<memory.h>
#include<map>
#include<queue>
#include <deque>
#include <list>
#include <stack>
#include <vector>
#include<set>
#define Maxn   1005
typedef long long ll;
#define rep(i,j,n) for(int i=j;i<=n;i++)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define lowbit(a) a&-a
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
using namespace std;
int dp[Maxn];
int w[Maxn],v[Maxn];
int main()
{   int T,n,V;
    scanf("%d",&T);
    while(T--)
    {   scanf("%d%d",&n,&V);
        rep(i,1,n)
        scanf("%d",&v[i]);
        rep(i,1,n)
        scanf("%d",&w[i]);
        memset(dp,0,sizeof(dp));
        rep(i,1,n)
            per(j,V,w[i])
            dp[j]=Max(dp[j],dp[j-w[i]]+v[i]);
        printf("%d\n",dp[V]);
    }
    return 0;
}



你可能感兴趣的:(hdu2602-Bone Collector(01背包模版题))