• CF19B Checkout Assistant(背包dp)


    linkkk
    题意:
    有 n 件商品,每件有价格 ci 和扫描时间 ti。当正在扫描时,可以花费 1 秒偷走一件。求最少付钱数。扫描商品顺序任意。
    思路:
    扫描物品(i)可以得到(t_i+1)件物品,问题可以转化成(n)个物品,体积为(t_i+1),价值为(c_i)
    求得到至少(n)件物品所需的最小价值
    代码:

    #include<bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    typedef pair<int, int>PII;
    
    inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
    
    inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
    
    #define read read()
    
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    
    ll ksm(ll a, ll b,ll mod){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
    
    const int maxn=2e5+7,inf=0x3f3f3f3f;
    
    ll t[2100],c[2100],dp[4100];
    
    int main(){
        int n=read;
        ll maxx=0ll;
        rep(i,1,n){
            t[i]=read+1,c[i]=read;
            maxx=max(maxx,t[i]);
        }
        memset(dp,0x3f,sizeof dp);
        dp[0]=0;
        maxx+=n;
        for(int i=1;i<=n;i++)
            for(int j=maxx;j>=t[i];j--)
                dp[j]=min(dp[j],dp[j-t[i]]+c[i]);
        ll ans=1e18;
        for(int i=n;i<=maxx;i++) ans=min(ans,dp[i]);
        cout<<ans;
    
    
    
    
    
        return 0;
    }
    /*
    
    
    */
    
    
    
    
    
    /**/
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  • 相关阅读:
    枚举
    泛型
    装箱和拆箱
    使用TryParse()来执行数值转换
    参数数组
    checked和unchecked转换
    字符串不可变
    TCC : Tiny C Compiler (2018-2-6)
    win10 下 protobuf 与 qt
    QWebView 与Js 交互
  • 原文地址:https://www.cnblogs.com/OvOq/p/15257410.html
Copyright © 2020-2023  润新知