Codeforces Round #436 E
思路:排序+背包,对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 ("\n") #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; }