zoukankan      html  css  js  c++  java
  • H

    https://codeforces.com/problemset/problem/864/E

    这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影响到之前的。

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <algorithm>
    #define inf 0x3f3f3f3f
    using namespace std;
    const int maxn = 2e3 + 10;
    
    struct node
    {
        int t, p, d, id;
    }exa[maxn];
    
    bool cmp(node a,node b)
    {
        return a.d < b.d;
    }
    
    int G[110][2200];
    int dp[2200];
    
    int main()
    {
        int n;
        int V = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%d%d", &exa[i].t, &exa[i].d, &exa[i].p);
            exa[i].id = i;
            V = max(V, exa[i].d);
        }
        sort(exa + 1, exa + 1 + n, cmp);
        //for (int i = 1; i <= n; i++) printf("www %d %d %d
    ", exa[i].t, exa[i].d, exa[i].p);
        int ex = 0, x = 0, y = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = exa[i].d-1; j >= exa[i].t; j--)
            {
                if (dp[j - exa[i].t] + exa[i].p > dp[j])
                {
                    dp[j] = dp[j - exa[i].t] + exa[i].p;
                    G[i][j] = 1;
                }
                if(dp[j]>ex)
                {
                    ex = dp[j];
                    x = i, y = j;
                }
            }
        }
        printf("%d
    ", ex);
        stack<int>ans;
        int i = x, j = y;
        while (i > 0)
        {
            if(G[i][j])
            {
                ans.push(exa[i].id);
                j -= exa[i].t;
            }
            i -= 1;
        }
        printf("%d
    ", (int)ans.size());
        while(!ans.empty())
        {
            printf("%d ", ans.top());
            ans.pop();
        }
        printf("
    ");
        return 0;
    }
  • 相关阅读:
    Let和Const的使用
    Spring框架学习10——JDBC Template 实现数据库操作
    python 学习
    delphi
    mysql 客户端连接报错Illegal mix of collations for operation
    tnsping 不通
    orm总结
    other
    resultset 查询时返回多个相同值
    vlan 知识学习
  • 原文地址:https://www.cnblogs.com/EchoZQN/p/10925376.html
Copyright © 2011-2022 走看看