• ZOJ 3769 Diablo III


    描述

    Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new expansion of Diablo III, has been released! On hearing the news, the crazy video game nerd Yuzhi shouted: "I'm so excited! I'm so excited! I wanna kill the Diablo once more!"

    The ROS introduced a lot of new features and changes. For example, there are two new attributes for players in the game: Damage and Toughness. The attribute Damage indicates the amount of damage per second you can deal and the Toughness is the total amount of raw damage you can take.

    To beat the Diablo, Yuzhi need to select the most suitable equipments for himself. A player can carry at most 13 equipments in 13 slots: Head, Shoulder, Neck, Torso, Hand, Wrist, Waist, Legs, Feet, Shield, Weapon and 2 Fingers. By the way, there is a special type of equipment: Two-Handed. A Two-Handed equipment will occupy both Weapon and Shield slots.

    Each equipment has different properties on Damage and Toughness, such as a glove labeled "30 20" means that it can increase 30 Damage and 20 Toughness for the player who equips it in the Hand slot. The total Damage and Toughness is the sum of Damage and Toughness of all equipments on the body. A player without any equipments has 0 Damage and 0 Toughness.

    Yuzhi has N equipments stored in his stash. To fight against the Diablo without lose the battle, he must have at least M Toughness. In addition, he want to finish the battle as soon as possible. That means the Damage should be as much as possible. Please help Yuzhi to determine which equipments he should take.

    输入

    There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:

    The first line contains 2 integers N (1 <= N <= 300) and M (0 <= M <= 50000). The next N lines are the description of equipments. The i-th line contains a string Si and two integers Di and Ti (1 <= Di, Ti <= 50000). Si is the type of equipment in {"Head", "Shoulder", "Neck", "Torso", "Hand", "Wrist", "Waist", "Legs", "Feet", "Finger", "Shield", "Weapon", "Two-Handed"}. Di and Ti are the Damage and Toughness of this equipment.

    输出

    For each test case, output the maximum Damage that Yuzhi can get, or -1 if he can not reach the required Toughness.

    样例输入

    2
    1 25
    Hand 30 20
    5 25
    Weapon 15 5
    Shield 5 15
    Two-Handed 25 5
    Finger 5 10
    Finger 5 10
    

    样例输出

    -1
    35
    
      1 #include <stdio.h>
      2 #include <string>
      3 #include <map>
      4 #include <vector>
      5 #include <iostream>
      6 #define MAXN 310
      7 using namespace std;
      8 
      9 int n,m;
     10 map< string , int > M;
     11 
     12 int max(int a, int b){
     13     if(a>b)return a;
     14     else return b;
     15 }
     16 
     17 void init(){
     18     M["Head"]=0;
     19     M["Shoulder"]=1;
     20     M["Neck"]=2;
     21     M["Torso"]=3;
     22     M["Hand"]=4;
     23     M["Wrist"]=5;
     24     M["Waist"]=6;
     25     M["Legs"]=7;
     26     M["Feet"]=8;
     27     M["Shield"]=9;//finger
     28     M["Weapon"]=10;
     29     M["Finger"]=11;
     30     M["Two-Handed"]=12;
     31 }
     32 
     33 struct Node
     34 {
     35     int d,t;
     36 }nod;
     37 
     38 vector<Node> V[13];//存储同类物品
     39 int dp[13][50001];
     40 int vd,vt;
     41 
     42 void read(){
     43     int i,j,d,t;
     44     char ch[30];
     45     scanf("%d %d" ,&n ,&m);
     46     for(i=0; i<13; i++){
     47         V[i].clear();
     48     }
     49     for(i=0; i<n; i++){
     50         scanf("%s %d %d" ,ch , &d ,&t);
     51         int index=M[string(ch)];
     52         nod.d=d;
     53         nod.t=t;
     54         V[index].push_back( nod );
     55         if(index==9 || index==10){
     56             V[12].push_back( nod );
     57         }
     58     }
     59     //两只手的装备
     60     for(i=0; i<V[9].size(); i++){
     61         for(j=0; j<V[10].size(); j++){
     62             nod.d=V[9][i].d+V[10][j].d;
     63             nod.t=V[9][i].t+V[10][j].t;
     64             V[12].push_back( nod );  
     65         }
     66     }
     67     //存戒指
     68     V[9].clear();
     69     for(i=0; i<V[11].size(); i++){
     70         V[9].push_back( V[11][i] );
     71         for(j=i+1; j<V[11].size(); j++){
     72             nod.d=V[11][i].d+V[11][j].d;
     73             nod.t=V[11][i].t+V[11][j].t;
     74             V[9].push_back( nod );
     75         }
     76     }
     77     V[11].clear();
     78 }
     79 
     80 int main(){
     81     init();
     82     int t;
     83     int i,j,k;
     84     scanf("%d" ,&t);
     85     while( t-- ){
     86         read();
     87         memset(dp,-1,sizeof(dp));
     88         //12单独处理一下,存到9
     89         dp[10][0]=0;
     90         for(i=0; i<V[12].size(); i++){
     91             nod=V[12][i];
     92             if(nod.t>m){
     93                 vt=m;
     94             }else{
     95                 vt=nod.t;
     96             }
     97             vd=nod.d;
     98             dp[10][vt]=max( dp[10][vt] , vd );
     99         }
    100         for(k=9; k>=0; k--){
    101             for(j=0; j<=m; j++){
    102                 dp[k][j]=max( dp[k][j],dp[k+1][j] );
    103                 if( dp[k+1][j]==-1 )continue;
    104                 /*
    105                     dp[k][j] 表示k件装备,它所用的防御是j的伤害
    106                     当前装备伤害+之前伤害最大值
    107                     dp[k][vt]=max( dp[k][vt], nod.d+dp[k+1][j] )
    108                 */
    109                 for(i=0; i<V[k].size(); i++){
    110                     nod=V[k][i];
    111                     if( nod.t +j > m ){
    112                         vt=m;
    113                     }else{
    114                         vt=nod.t +j;
    115                     }
    116                     dp[k][vt]=max( dp[k][vt], nod.d+dp[k+1][j] );
    117                 }
    118             }
    119         }
    120         printf("%d
    " ,dp[0][m]);
    121     }
    122     return 0;
    123 }
  • 相关阅读:
    Java面试题
    verilog之锁存器和触发器
    verilog基本语法之always和assign
    verilog之基本结构
    ZYNQ7000系列学习之TF卡读写实验
    英语文档阅读学习系列之ZYNQ-7000 All Programmable SOC Packaging and Pinout
    物理之纳电子
    英语文档阅读学习系列之Zynq-7000 EPP Software Developers Guide
    嵌入式C语言设计学习
    ZYNQ7000系列学习之自定义模块构成IP
  • 原文地址:https://www.cnblogs.com/chenjianxiang/p/3654125.html
Copyright © 2020-2023  润新知