zoukankan      html  css  js  c++  java
  • ZOJ

    ZOJ - 3703

    思路:

    背包dp

    为了使最后的罚时最少,先按做题所需时间排序

    运算符重载方便背包转移。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define fi first
    #define se second
    #define LL long long
    #define pb push_back
    #define pii pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    
    const int N = 1e3 + 10;
    pii t[55];
    struct node {
        int x, y, z;
        bool operator < (const node & t) const {
            if(x == t.x) {
                if(y == t.y) {
                    if(z == t.z) {
                        return true;
                    }
                    else return z > t.z;
                }
                else return y < t.y;
            }
            else return x < t.x;
        }
    }dp[N];
    int main() {
        int cs, T, n;
        scanf("%d", &cs);
        while(cs--) {
            scanf("%d%d", &T, &n);
            for (int i = 1; i <= n; i++) scanf("%d", &t[i].fi);
            for (int i = 1; i <= n; i++) scanf("%d", &t[i].se);
            sort(t+1, t+1+n);
            for (int j = 0; j <= T; j++) dp[j].x = dp[j].y = dp[j].z = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = T; j >= t[i].fi; j--) {
                    dp[j] = max(dp[j],node{dp[j-t[i].fi].x+t[i].se, dp[j-t[i].fi].y+1, dp[j-t[i].fi].z+j});
                }
            }
            node ans = {0, 0, 0};
            for (int j = 0; j <= T; j++) {
                ans = max(ans, dp[j]);
            }
            printf("%d %d %d
    ", ans.x, ans.y, ans.z);
        }
        return 0;
    }
  • 相关阅读:
    python--模块导入与执行
    python--re模块
    python--递归函数
    CSRF攻击与防御
    XSS跨站脚本攻击
    HTTP协议详解以及URL具体访问过程
    Git服务器搭建
    浅谈PHP异常处理
    常用的几个PHP加密函数
    PHP将数据导出Excel表中(投机型)
  • 原文地址:https://www.cnblogs.com/widsom/p/9015119.html
Copyright © 2011-2022 走看看