zoukankan      html  css  js  c++  java
  • Codeforces Round #436 E

    Fire

    思路:排序+背包,对d排序然后跑背包

    AC代码:

    #include "iostream"
    #include "iomanip"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #pragma comment(linker, "/STACK:102400000,102400000")
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a,x) memset(a,x,sizeof(a))
    #define step(x) fixed<< setprecision(x)<<
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    #define ll long long
    #define endl ("
    ")
    #define ft first
    #define sd second
    #define lrt (rt<<1)
    #define rrt (rt<<1|1)
    using namespace std;
    const ll mod=1e9+7;
    const ll INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const double PI=acos(-1.0);
    const int N=1e5+100;
    
    struct Node{
        int t,d,p,id;
        bool friend operator< (Node a, Node b){
            return a.d<b.d;
        }
    }a[105];
    
    int n,dp[2055],ans=0,t=0,mx=0;
    vector<int> vex[2055];
    int main(){
        scanf("%d",&n);
        for(int i=1; i<=n; ++i){
            scanf("%d%d%d",&a[i].t,&a[i].d,&a[i].p);
            a[i].id=i; mx=max(mx,a[i].d);
        }
        sort(a+1,a+1+n);
        for(int i=1; i<=n; ++i){
            for(int j=a[i].d-a[i].t-1; j>=0; --j){
                dp[j+a[i].t]=dp[j+a[i].t];
                if(dp[j+a[i].t] < dp[j]+a[i].p){
                    dp[j+a[i].t]=dp[j]+a[i].p;
                    vex[j+a[i].t]=vex[j];
                    vex[j+a[i].t].pb(a[i].id);
                }
            }
        }
        for(int j=0; j<=mx+50; ++j){
            if(dp[j]>ans){
                ans=dp[j];
                t=j;
            }
        }
        cout<<ans<<endl<<vex[t].size()<<endl;
        for(auto i : vex[t]){
            cout<<i<<" ";
        }
        return 0;
    }
  • 相关阅读:
    日总结07
    Flask使用json或jsonify返回响应的数据
    日总结06
    tensorflow 代码流程02
    日总结05
    题解 P1505 [国家集训队]旅游
    数学期望
    常用软件
    HTMLHelper
    DateHelper(辅助类)
  • 原文地址:https://www.cnblogs.com/max88888888/p/7607104.html
Copyright © 2011-2022 走看看