zoukankan      html  css  js  c++  java
  • 樱花 混合背包

    樱花

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #include <cassert>
    //#include <unordered_set>
    //#include <unordered_map>
    #define ll              long long
    #define pii             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define forn(i, n)      for(int i = 0; i < int(n); i++)
    using namespace std;
    int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = acos(-1.0);
    const double eps = 1e-6;
    const ll mod = 1e9 + 7;
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    inline ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    void exgcd(ll A, ll B, ll& x, ll& y)
    {
        if (B) exgcd(B, A % B, y, x), y -= A / B * x; else x = 1, y = 0;
    }
    inline int qpow(int x, ll n) {
        int r = 1;
        while (n > 0) {
            if (n & 1) r = 1ll * r * x % mod;
            n >>= 1; x = 1ll * x * x % mod;
        }
        return r;
    }
    inline int inv(int x) {
        return qpow(x, mod - 2);
    }
    ll lcm(ll a, ll b)
    {
        return a * b / gcd(a, b);
    }
    
    /**********************************************************/
    const int N = 1e4 + 5;
    int t0[N], c[N], p[N], dp[N];
    int t, t1, t2, n;
    
    void completepack(int cost, int weight)
    {
        rep(i, 0, t)
        {
            if (i >= cost)
                dp[i] = max(dp[i], dp[i - cost] + weight);
        }
    }
    
    void zopack(int cost, int weight)
    {
        dec(i, t, 0)
        {
            if(i>=cost)
                dp[i] = max(dp[i], dp[i - cost] + weight);
        }
    }
    
    void multipack(int cost, int weight, int amount)
    {
        if (cost * amount >= t)
        {
            completepack(cost, weight);
            return;
        }
        int k = 1;
        while (k < amount)
        {
            zopack(k * cost, k * weight);
            amount -= k;
            k *= 2;
        }
        zopack(amount * cost, amount * weight);
    }
    
    int tonum(string s)
    {
        int h = 0;
        int pos = 0;
        for (pos = 0; s[pos] != ':'; pos++)
        {
            h = h * 10 + s[pos] - '0';
        }
        pos++;
        int m = 0;
        for (; pos < s.size(); pos++)
        {
            m = m * 10 + s[pos] - '0';
        }
        return h * 60 + m;
    }
    
    int main()
    {
    #ifdef _DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
        string s1, s2;
        cin >> s1 >> s2 >> n;
        t1 = tonum(s1);
        t2 = tonum(s2);
        t = t2 - t1;
        rep(i, 1, n)
        {
            cin >> t0[i] >> c[i] >> p[i];
        }
        rep(i, 1, n)
        {
            if (p[i] == 0)
                completepack(t0[i], c[i]);
            else
                multipack(t0[i], c[i], p[i]);
        }
        cout << dp[t] << endl;
        return 0;
    }
     
  • 相关阅读:
    Brain network involved in autonomic functions 与自主功能相关的大脑网络
    Brief summary of classical components of ERP 事件相关成分(ERP)经典成分小结
    ICA & Percentage Variance Account For (PVAF)
    数据处理中白化Whitening的作用图解分析
    Loadings vs eigenvectors in PCA 主成分分析(PCA)中的负荷和特征向量
    主成分分析(PCA)和独立成分分析(ICA)相关资料
    Sketch of heart and QRS complex 心脏及QRS波群简图
    Brain Network visulation in EEG 脑电网络可视化
    Phase Locking Value (PLV) 神经信号的锁相值
    ubuntu16.04下的一些基本操作笔记
  • 原文地址:https://www.cnblogs.com/dealer/p/13681357.html
Copyright © 2011-2022 走看看