链接http://acm.hdu.edu.cn/showproblem.php?pid=6508


题目:

Problem Description
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
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
 
Output
One integer representing the maximum total damage.
 
Sample Input
3 3
3 3 1 1
2 3 1 1
1 3 1 1
4 3
3 3 1 1
3 4 1 0
1 3 0 1
1 0 1 0
 
Sample Output
9
7
 
 

题意:

给出四种卡片 既是魔法卡也是增幅卡 是魔法卡不是增幅卡 是增幅卡不是魔法卡 不是增幅卡也不是魔法卡

每一张卡片都包含两个值 打出牌的代价 和打出牌的价值

其中魔法卡的作用是使所有未使用的增幅卡代价减1 如果代价已经为0就不减了

思路:

从增幅卡和魔法卡的作用中可以看出来 打出这四种牌是有先后顺序的 增幅卡要尽可能后打出 魔法卡要尽可能先打出

我采用的顺序是 是魔法卡不是增幅卡>是增幅卡不是魔法卡>既是魔法卡也是增幅卡>不是增幅卡也不是魔法卡

然后采用三维dp来转移 dp[i][j][k]表示的是当前已经打出的伤害和 i表示当前已经打到的第i张牌 j表示当前已经打出的增幅卡的数量 k表示当前已经用掉的代价和

直接用三维去存储的话存不下 采用了滚动数组去滚掉第一维i(当前的位置只依赖上一位 可以采用滚动数组只记录两个值 i%2和(i-1)%2)


代码:

#include <bits/stdc++.h>

using namespace std;
const int maxn=;
int n,W;
int dp[][maxn][maxn]; struct node{
int w,x,vis1,vis2;
}kk[maxn]; int cmp(node a,node b){
if(a.vis1!=b.vis1) return a.vis1>b.vis1;
if(a.vis2!=b.vis2) return a.vis2<b.vis2;
return a.w<b.w;
} int main(){
// freopen("1.in","r",stdin);
while(~scanf("%d%d",&n,&W)){
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&kk[i].w,&kk[i].x,&kk[i].vis1,&kk[i].vis2);
}
sort(kk+,kk++n,cmp);
memset(dp[],-,sizeof(dp[]));
dp[][][]=;
// cout<<n<<endl;
for(int i=;i<=n;i++){
memset(dp[i%],-,sizeof(dp[i%]));
for(int j=;j<=i;j++){
for(int k=;k<=W;k++){
// if(dp[(i-1)%2][j][k]==-1) continue;
dp[i%][j][k]=dp[(i-)%][j][k];
if(kk[i].vis1== && kk[i].vis2== && j->= && k-max(kk[i].w-(j-),)>= && dp[(i-)%][j-][k-max(kk[i].w-(j-),)]!=-)
dp[i%][j][k]=max(dp[i%][j][k],dp[(i-)%][j-][k-max(kk[i].w-(j-),)]+kk[i].x); //既是魔法卡也是增幅卡
if(kk[i].vis1== && kk[i].vis2== && k-max(kk[i].w-j,)>= && dp[(i-)%][j][k-max(kk[i].w-j,)]!=-)
dp[i%][j][k]=max(dp[i%][j][k],dp[(i-)%][j][k-max(kk[i].w-j,)]+kk[i].x); //只是增幅卡
if(kk[i].vis1== && kk[i].vis2== && j->= && k-kk[i].w>= && dp[(i-)%][j-][k-kk[i].w]!=-)
dp[i%][j][k]=max(dp[i%][j][k],dp[(i-)%][j-][k-kk[i].w]+kk[i].x); //只是魔法卡
if(kk[i].vis1== && kk[i].vis2== && k-kk[i].w>= && dp[(i-)%][j][k-kk[i].w]!=-)
dp[i%][j][k]=max(dp[i%][j][k],dp[(i-)%][j][k-kk[i].w]+kk[i].x); //什么都不是
}
}
}
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=W;j++){
ans=max(ans,dp[n%][i][j]);
}
}
printf("%d\n",ans);
}
return ;
}

HDOJ 6508 Problem I. Spell Boost (01背包/DP)的更多相关文章

  1. noj [1479] How many (01背包||DP||DFS)

    http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...

  2. PAT L3-001 凑零钱(01背包dp记录路径)

    韩梅梅喜欢满宇宙到处逛街.现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债.韩梅梅手边有104枚来自各个星球的硬币,需要请你帮她盘算一下,是 ...

  3. HDOJ 1203 I NEED A OFFER!(01背包)

    10397507 2014-03-25 23:30:21 Accepted 1203 0MS 480K 428 B C++ 泽泽 题目链接:http://acm.hdu.edu.cn/showprob ...

  4. 饭卡------HDOJ杭电2546(还是01背包!!!!!!)

    Problem Description 电子科大本部食堂的饭卡有一种非常诡异的设计,即在购买之前推断剩余金额. 假设购买一个商品之前,卡上的剩余金额大于或等于5元,就一定能够购买成功(即使购买后卡上剩 ...

  5. HDU 1203 I NEED A OFFER!(01 背包DP)

    点我看题目 题意 : 中文题不详述. 思路 :类似于01背包的DP,就是放与不放的问题,不过这个要求概率,至少得到一份offer的反面就是一份也得不到,所以先求一份也得不到的概率,用1减掉就可以得到所 ...

  6. (01背包 dp)P1049 装箱问题 洛谷

    题目描述 有一个箱子容量为VV(正整数,0≤V≤20000),同时有nn个物品(0<n≤30,每个物品有一个体积(正整数). 要求nn个物品中,任取若干个装入箱内,使箱子的剩余空间为最小. 输入 ...

  7. 0-1背包dp|波动数列|2014年蓝桥杯A组10-fishers

    标题:波动数列 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. 栋栋对这种数列很好奇,他想知道长度为 n 和为 s 而且后一项总是比前一项增加a ...

  8. HDU 2602 Bone Collector (01背包DP)

    题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...

  9. Bookshelf 2(poj3628,01背包,dp递推)

    题目链接:Bookshelf 2(点击进入) 题目解读: 给n头牛,给出每个牛的高度h[i],给出一个书架的高度b(所有牛的高度相加>书架高度b),现在把一些牛叠起来(每头牛只能用一次,但不同的 ...

随机推荐

  1. 云计算openstack共享组件(2)——Memcache 缓存系统

    一.缓存系统 在大型海量并发访问网站及openstack等集群中,对于关系型数据库,尤其是大型关系型数据库,如果对其进行每秒上万次的并发访问,并且每次访问都在一个有上亿条记录的数据表中查询某条记录时, ...

  2. 关于取li中的value

    HTML的li标签的属性value是有规定的:规定列表项目的数字,所以它的value只能是数字.像字符和第一数字为0的都不取非要用li的话可以 var uid = $('#userid').attr( ...

  3. 石家庄地铁系统开发(java web版)(一)

    今天所完成的任务: 在Mysql数据库中创建了sjzsubstop表和sjzsubway表 sjzsubstop表用于录入所有站点名称和与之对应的stopid(作为主码) sjzsubway表用于录入 ...

  4. storybook实践

    很久之前就听说过storybook,一直想实践一下

  5. 关于echarts.js 柱形图

    echarts.js官网: http://www.echartsjs.com/index.html 这是我所见整理最详细echarts.js 柱形图博客: https://blog.csdn.net/ ...

  6. Spring Boot 2.x 编写 RESTful API (六) 事务

    用Spring Boot编写RESTful API 学习笔记 Transactional 判定顺序 propagation isolation 脏读 不可重复读 幻读 不可重复读是指记录不同 (upd ...

  7. c语言利用读取命令行(多行读取)

    #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { FILE *fh = po ...

  8. Git-01-上传项目到github

    function fun1(){ Git上传项目到github Folder-->Git bash here Execute command: --git clone 仓库地址     多出一个 ...

  9. bash中打印文件每一行及其行号

    #!/bin/bash linenumber=$(cat remoteIP.cfg |wc -l) currentline= for ip in $(cat remoteIP.cfg) do curr ...

  10. M-BM-

    今天拷贝了一段代码 struct    Test       {               Test(    int    )    {}               Test()    {}    ...