Finally, the Chinese question ....
At the time of the exam on the test of this problem .... Decisive GG.
Ideas:
Because it is possible to have a dependency ring, it is necessary to tarjan the dots first.
Then it's just a tree-shaped DP.
x represents the current node. J means the maximum amount of software that can put in the space of J.
State transition equation: F[x][j]=max (f[x][j],f[x.son][k]+f[x][j-k])
The title says: Software I can only work correctly if software J (including the direct or indirect reliance of software J) is installed
How do you translate this sentence? directly to the w[i] below the value set to negative infinity is good.
by Siriusren #include <cstdio> #include <cstring> #include <algorithm> using namespace std;
int n,m,xx,t=0,tot=0,cnt=0,top=0,maxx=0,low[105],dfn[105],s[105],p[105],d[105],f[505][505];
int first[105],next[105],v[105],w[105],ww[105],v[105],vv[105],vis[105],in[105]; void Add (int x,int y) {v[tot]=y,next[tot]=first[x];first[x]=tot++} void Tarjan (int x) {Low[x]=dfn[x]=++cnt;vis[x]=1;s
[++top]=x;
for (int i=first[x];~i;i=next[i]) if (!dfn[v[i]]) Tarjan (v[i)), Low[x]=min (Low[x],low[v[i]);
else if (Vis[v[i]]) low[x]=min (Low[x],dfn[v[i]);
if (Low[x]==dfn[x]) {t++;d o xx=s[top--],vis[xx]=0,p[xx]=t,ww[t]+=w[xx],vv[t]+=v[xx];while (xx!=x);}}
void Dfs (int x) {for (int i=first[x];~i;i=next[i]) {DFS (v[i]);
for (int j=m;j>=0;j--) for (int k=j;k>=0;k--) F[x][j]=max (f[x][j],f[v[i]][k]+f[x][j-k));
int main () {memset (first,-1,sizeof (a));
memset (F,0xcf,sizeof (f));
scanf ("%d%d", &n,&m); for (int i=1;i<=n;i++) scanf ("%d", &w[i]);
for (int i=1;i<=n;i++) scanf ("%d", &v[i]);
for (int i=1;i<=n;i++) scanf ("%d", &d[i]), add (d[i],i);
for (int i=0;i<=n;i++) if (!dfn[i]) Tarjan (i);
memset (First,-1,sizeof (a));
for (int i=1;i<=n;i++) if (P[d[i]]!=p[i]) Add (P[d[i]],p[i]), in[p[i]]++;
for (int i=1;i<=t;i++) if (!in[i]&&i!=p[0]) Add (p[0],i);
for (int i=1;i<=t;i++) for (int j=ww[i];j<=m;j++) f[i][j]=vv[i];
DFS (p[0]);
printf ("%d\n", F[p[0]][m]); }