首页 > 代码库 > TYVJ1275

TYVJ1275

一道水题01背包,因为一时疏忽WA了4次RE1次
这题不一样的地方就是打每个小怪必须打死
也就是说每个小怪两下打不死要认为是三下。背包容量k,物品数量n
dp[j] = max(dp[j],dp[j-w[i]]+v[i]);

 

//667672#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;const int maxn = 105;const int maxv = 25;int dp[maxv],w[maxn],v[maxn];int main(){    //freopen("in.txt","r",stdin);    int n,m,k;    cin>>n>>m>>k;    for(int i = 1;i<=n;++i)cin>>w[i];    for(int i = 1;i<=n;++i)cin>>v[i];    if(!m || k==0){printf("0\n");return 0;}//    for(int i = 1;i<=m;++i)dp[i]=-INF;//    dp[0] = 0;    memset(dp,0,sizeof(dp));    for(int i = 1;i<=n;++i)    {        if(w[i]%m)w[i] = w[i]/m+1;        else w[i]/=m;        for(int j = k;j>=w[i];--j)            dp[j] = max(dp[j],dp[j-w[i]]+v[i]);    }    printf("%d\n",dp[k]);    return 0;}

 

TYVJ1275