• Codeforces 1107F Vasya and Endless Credits dp(看题解)


    Vasya and Endless Credits

    感觉是很巧妙的dp啊, 想到了分成两种信用卡, 并且有一种需要按b排序, 但是没想出怎么dp。。

    #include<bits/stdc++.h>
    #define LL long long
    #define LD long double
    #define ull unsigned long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ALL(x) (x).begin(), (x).end()
    #define fio ios::sync_with_stdio(false); cin.tie(0);
    
    using namespace std;
    
    const int N = 500 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1e-8;
    const double PI = acos(-1);
    
    template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
    template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
    template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
    template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}
    
    int n;
    LL dp[N][N];
    
    struct Node {
        int a, b, k;
        void read() {
            scanf("%d%d%d", &a, &b, &k);
        }
        bool operator < (const Node &rhs) const {
            return b > rhs.b;
        }
    } offers[N];
    
    int main() {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) offers[i].read();
        sort(offers + 1, offers + 1 + n);
        LL ans = 0;
        memset(dp, 0xc0, sizeof(dp));
        dp[0][0] = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 0; j <= i; j++) {
                chkmax(dp[i][j], dp[i - 1][j]);
                chkmax(dp[i][j], dp[i - 1][j] + offers[i].a - 1LL * offers[i].k * offers[i].b);
                if(j) chkmax(dp[i][j], dp[i - 1][j - 1] + offers[i].a - 1LL * (j - 1) * offers[i].b);
                chkmax(ans, dp[i][j]);
            }
        }
        printf("%lld
    ", ans);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    TensorFlowMNIST数据集逻辑回归处理
    TensorFlow多元线性回归实现
    TensorFlow简单线性回归
    mysql ON DUPLICATE KEY UPDATE
    20200908 morning diary
    LambdaUtil
    数据库SQL自我书写册
    getMyFriendsListFromWeChat()
    MySQL8.*的JSON语法知多少
    Exception in thread "main" java.lang.IllegalArgumentException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token at [Source: UNKNOWN; line: -1, c
  • 原文地址:https://www.cnblogs.com/CJLHY/p/11111438.html
Copyright © 2020-2023  润新知