Transmission Door
Test instructions:\ (n\) location, each location has value \ (v_i\) and weight \ (p_i\), to select some locations, if you want to choose the location \ (i\), then the weight of the front selected for the sum of \ (l_i\), the sum of the weights to be chosen for \ (r_i\), to find a solution to make the value and maximum
This restriction is very comfortable, can set \ (f_i\) to start from the front, select the maximum value of the first \ (i\) , transfer enumeration before the \ (j\), if you can transfer from \ (j\) , according to the conditions, requirements \ (l_i=l_j+p_i\&\&r_i=r_j-p_i\), a transfer prefix can be output scheme
But this is not good, we can find that for a \ (i\), only \ (l_j+p_j+r_j=l_i+p_i+r_i\) \ (j\) can transfer over, so you can put all the \ (l_i+ p_i+r_i\) are placed equally in a group, in each group, the notation \ (f_k\) for the maximum value of the prefix weight of \ (k\) , shifted from the previous enumeration \ (i\), from \ (f_{l_i}\) transfer to \ (f_{l_i+p_i}\) , the answer for this group should be \ (f_{l_i+p_i+r_i}\)
Code thief ugly, light \ (\mathfrak{d}\)Qwq
#include <bits/stdc++.h> #define IL inline#define re register#define LL long long#define ull unsigned long long#defin E db double#define EPS (1e-7) using namespace Std;const int N=200000+10,m=3000000+10;il LL Rd () {ll x=0,w=1;char ch=0; while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') W=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x= (x<<3) + (x<<1) + (ch^48); Ch=getchar ();} return x*w;} int F[m],hd[m],nt[n];int n,a[n][4],ma;int St[n],an[n],tt=0,pre[n],g[m];int main () {n=rd (); for (int i=1;i<=n;i++) {a[i][0]=rd (), A[i][1]=rd (), A[i][2]=rd (), A[i][3]=rd (); int pp=a[i][1]+a[i][2]+a[i][3]; Ma=max (MA,PP); Nt[i]=hd[pp],hd[pp]=i; } memset (F,-63,sizeof (f)); f[0]=0; int ii=-1,ans=0,inf=f[1]; for (int h=0;h<=ma;h++) {if (!hd[h]) continue; int st[n],tt=0; for (int i=hd[h];i;i=nt[i]) st[++tt]=i; for (int i=tt;i>=1;i--) F[a[st[i]][1]+a[st[i]][2]]=max (f[a[st[i]][1]+a[st[i]][2]],f[a[st[i]][2]]+a[st[i]][0]); if (ans<F[H]) ans=f[h],ii=h; for (int i=tt;i>=1;i--) F[a[st[i]][1]+a[st[i]][2]]=inf; }//printf ("%d\n", ans); if (ii>=0) {for (int i=hd[ii];i;i=nt[i]) st[++tt]=i; for (int i=tt;i>=1;i--) if (f[a[st[i]][1]+a[st[i]][2]]<f[a[st[i]][2]]+a[st[i]][0]) f[a[st[i]][1]+a[st[ I]][2]]=f[a[st[i]][2]]+a[st[i]][0],pre[st[i]]=g[a[st[i]][2]],g[a[st[i]][1]+a[st[i]][2]]=st[i]; tt=0; int NW=G[II]; while (NW) {AN[++TT]=NW,NW=PRE[NW]; } printf ("%d\n", TT); for (int i=tt;i>=1;i--) printf ("%d", an[i]); } else puts ("0"); return 0;}
cf28d Don t fear, dravde is kind