zoukankan      html  css  js  c++  java
  • 2018 东北赛i 简单dpI

    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
    

    就是一个带顺序的背包 极其简单

    还有就是注意一下斜背包的时候的枚举顺序

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    struct node
    {
        int w,x;
        int ma,bo;
    };
    node a[509];
    int dp[505][505];//mo  huafei
    int cmp (node p,node q)
    {
        if(p.ma==q.ma)
        {
            if(p.bo==q.bo)
            {
                return p.w<q.w;
            }
            return p.bo<q.bo;
        }
        return  p.ma>q.ma;
    }
    int main()
    {
        int n,w;
        while (~scanf("%d%d",&n,&w))
        {
            int sum=0;
            memset(dp,-1,sizeof(dp));
            for (int i=1; i<=n; i++)
            {
                scanf("%d%d%d%d",&a[i].w,&a[i].x,&a[i].ma,&a[i].bo);
            }
            sort(a+1,a+1+n,cmp);
    //        for(int i=1;i<=n;i++)
    //        {
    //            cout<<a[i].w<<a[i].x<<" "<<a[i].ma<<endl;
    //        }
            int MAX=0;
            dp[0][0]=0;
            for (int i=1; i<=n; i++) //mofaka
            {
                for(int j=w; j>=0; j--)
                {
                    for(int k=n; k>=0; k--)
                    {
    
                        if(a[i].ma==1)
                        {
                            int temp=max(a[i].w-k+1,0);
                            if(a[i].bo==0&&j-a[i].w>=0&&k>=1&&(dp[k-1][j-a[i].w]!=-1))
                                dp[k][j]=max(dp[k-1][j-a[i].w]+a[i].x,dp[k][j]);
                            if(a[i].bo==1&&j-temp>=0&&k>=1&&dp[k-1][j-temp]!=-1)
                                dp[k][j]=max(dp[k-1][j-temp]+a[i].x,dp[k][j]);
                        }
                        else
                        {
                            int temp=max(a[i].w-k,0);
                             if(a[i].bo==0&&j-a[i].w>=0&&(dp[k][j-a[i].w]!=-1))
                                dp[k][j]=max(dp[k][j-a[i].w]+a[i].x,dp[k][j]);
                            if(a[i].bo==1&&j>=temp&&dp[k][j-temp]!=-1)
                                dp[k][j]=max(dp[k][j-temp]+a[i].x,dp[k][j]);
                        }
                        //cout<<k<<" "<<j<<" "<<dp[k][j]<<endl;
                        MAX=max(MAX,dp[k][j]);
                    }
                }
            }
            printf("%d
    ",MAX);
    
        }return 0;
    }
  • 相关阅读:
    python爬虫之破解javascript-obfuscator的混淆加密
    python反爬之前端加密技术
    轻松截获 Selenium 中的 Ajax 数据
    macos安装selenium+浏览器驱动
    爬虫神器,对ajax加载的数据进行hook截取,无视带有加密参数的接口
    macos 配置apache,mysql,php,nginx环境
    对WX公众号文章的爬取分析
    对app的反爬测试之apk逆向分析-frida绕过ssl pinning检测
    macos 安装frida的坑
    简易OA漫谈之工作流设计(四,怎么支持会签)
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852277.html
Copyright © 2011-2022 走看看