题目描述
Shadowverse is a funny card game. One day you are playing a round of this game.
You have n cards, each with two attributes wi and xi. If you use card i, you will cost wi points of power and cause xi damage to the enemy.
Among them, there are two special types of cards: some cards are magic cards and some have “spell boost effect”. Everytime you have used a magic card, for each unused “spell boost effect” card i: if the the current cost of i (i.e. wi) is positive, then wi will be reduced by 1. Note that some cards may be both magic cards and have spell boost effect.
Now you have W points of power, you need to calculate maximum total damage you can cause.
输入
Input is given from Standard Input in the following format:
n W
w1 x1 is_magic1 is_spell_boost1
w2 x2 is_magic2 is_spell_boost2
.
.
wn xn is_magicn is_spell_boostn
Constraints
1 ≤ n ≤ 500
0 ≤ W, wi, xi ≤ 500, and all of them are integers.
is_magici means: If this card is magic card, the value is 1, otherwise the value is 0.
is_spell_boosti means: If this card has spell boost effect, the value is 1, otherwise 0
输出
One integer representing the maximum total damage.
样例输入
3 3
3 3 1 1
2 3 1 1
1 3 1 1
样例输出
9
来源/分类
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) x&(-x)
typedef pair<int,int>pa;
const int maxn=505;
int dp[2][maxn][maxn];
int n,w;
struct node
{
int w,x,ma,bo;
}ss[maxn];
bool cmp(node a,node b)
{
if(a.ma!=b.ma)
{
return a.ma>b.ma;
}
if(a.bo!=b.bo)
{
return a.bo<b.bo;
}
return a.w<b.w;
}
int main()
{
scanf("%d %d",&n,&w);
for(int i=1;i<=n;i++)
{
scanf("%d %d %d %d",&ss[i].w,&ss[i].x,&ss[i].ma,&ss[i].bo);
}
sort(ss+1,ss+1+n,cmp);
memset(dp[0],-1,sizeof(dp[0]));
dp[0][0][0]=0;
for(int i=1;i<=n;i++)
{
memset(dp[i%2],-1,sizeof(dp[i%2]));
for(int j=0;j<=i;j++)
{
for(int k=0;k<=w;k++)
{
if(dp[(i-1)%2][j][k]==-1)
{
continue;
}
dp[i%2][j][k]=max(dp[i%2][j][k],dp[(i-1)%2][j][k]);
int jj=j+ss[i].ma;
int ww=k+max(0,ss[i].w-j*ss[i].bo);
if(ww<=w)
{
dp[i%2][jj][ww]=max(dp[i%2][jj][ww],dp[(i-1)%2][j][k]+ss[i].x);
}
}
}
}
int ans=0;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=w;j++)
{
ans=max(ans,dp[n%2][i][j]);
}
}
printf("%d\n",ans);
return 0;
}