zoukankan      html  css  js  c++  java
  • UESTC 电子科大专题训练 DP-D

    UESTC 1606

    题意:中文题

    思路:混合背包

    AC代码:

    #include "iostream"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #define ll long long
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a) memset(a,0,sizeof(a))
    #define mp(x,y) make_pair(x,y)
    using namespace std;
    const long long INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const int N=1e5+100;
    const ll mod=1e9+7;
    
    int vol,dp[N],n,k,t[N],a[N],b[N];
    void zeroonepack(int cost,int weight){
        for(int i=vol; i>=cost; i--)
            dp[i]=max(dp[i],dp[i-cost]+weight);
    }
    
    void complete(int cost, int weight){
        for(int i=cost; i<=vol; i++)
            dp[i]=max(dp[i],dp[i-cost]+weight);
    }
    
    void mutilpack(int cost,int weight,int counts){
        if(counts*cost>vol){
            complete(cost,weight);
            return;
        }
        for(int i=1; i<counts; ){
            zeroonepack(cost*i,weight*i);
            counts-=i;
            i<<=1;
        }
        zeroonepack(cost*counts,weight*counts);
    }
    
    int main(){
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        cin>>n>>vol;
        for(int i=1; i<=n; ++i){
            cin>>t[i]>>a[i]>>b[i];
            if(t[i]==2) t[i]=1;
            else if(t[i]==1) t[i]=-1;
        }
        for(int i=1; i<=n; ++i){
            if(t[i]==-1) complete(b[i],a[i]);
            else mutilpack(b[i],a[i],t[i]);
        }
        cout<<dp[vol]<<endl;
        return 0;
    }
  • 相关阅读:
    类与继承
    闭包、原型链和继承
    ajax(下)和“承诺”
    ajax(上)
    Ubuntu电源键软关机设置
    金老师语录摘要(七)
    金老师语录摘要(六)
    金老师语录摘要(四)
    金老师语录摘要(三)
    金老师语录摘要(二)
  • 原文地址:https://www.cnblogs.com/max88888888/p/7202434.html
Copyright © 2011-2022 走看看