Tag: www code typedef show tells the print destination ref stream
Transmission Door
At first I thought this problem is a relatively normal group backpack, but the original problem is the limit of the number, this time there is volume (the space occupied by the software), but there seems to be no difference between the two ...
So I wrote a normal group backpack, and then a sample. I'm not going to tell you that I was 0 in the beginning, because I wrote it wrong.
Hand it over to see only 10 points ...
Came back to find that the original question is not a tree ... Orz, then we have a look at each ring, each ring inside all the software is either select all, or do not select, so directly as a strong connected component contraction point, the volume and value can be combined. just like the furnace, the fusion so we shrink point, then all the points into the 0 point to the virtual node edge, and then start the normal DP. But when I first found out that the diagram was built in reverse, it would not be a tree. But think of Tarjan to find strong connectivity components, because I put the tree built into the map, so certainly the original starting point should also be the starting point, the building is reversed, after the magical AC!
Take a look at the code.
#include <cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<cmath>#include<Set>#include<queue>#defineRep (i,a,n) for (int i = a;i <= n;i++)#definePer (i,n,a) for (int i = n;i >= a;i--)#defineEnter Putchar (' \ n ')using namespaceStd;typedefLong Longll;Const intM =1005;Const intINF =1000000009;Constll mod = 1e9+7;intRead () {intAns =0, op =1; CharCH =GetChar (); while(Ch <'0'|| CH >'9') { if(ch = ='-') op =-1; CH=GetChar (); } while(Ch >='0'&& CH <='9') {ans*=Ten; Ans+ = CH-'0'; CH=GetChar (); } returnAns *op;}structnode{intNext,to, from;} E[m<<1];intm,n,dp[m][m],v[m],x,y,head[m],ecnt,size[m],w[m],dfn[m],scc[m],idx,low[m],stack[m],top,cnt;intRdeg[m],tot;BOOLVis[m];voidAddintXinty) {e[++ecnt].to =y; E[ecnt].next=Head[x]; E[ECNT]. from=x; HEAD[X]=ecnt;}voidTarjan (intx) {Low[x]= Dfn[x] = + +idx; stack[++top] = x,vis[x] =1; for(inti = Head[x];i;i =E[i].next) { if(!dfn[e[i].to]) Tarjan (e[i].to), low[x] =min (low[x],low[e[i].to]); Else if(Vis[e[i].to]) low[x] =min (low[x],dfn[e[i].to]); } if(Low[x] = =Dfn[x]) { intp; CNT++; while(P = stack[top--])) {Scc[p]= Cnt,vis[p] =0, v[cnt] + = v[p],w[cnt] + =W[p]; if(p = = x) Break; } }}voidrebuild () {Rep (I,1, ecnt) { intR1 = Scc[e[i]. from],R2 =Scc[e[i].to]; if(R1! = r2) Add (R2,R1), rdeg[r1]++; } Rep (I,n+1, CNT) {dp[i][0] =V[i]; if(!rdeg[i]) Add (0, i); }}voidDfsintXintFA) { for(inti = Head[x];i;i =E[i].next) { intt =e[i].to; if(t = = FA)Continue; DFS (T,X); Per (J,m,1) {Rep (P,0, J-w[t]) dp[x][j] = max (dp[x][j],dp[x][j-p-w[t]) +dp[t][p]); } //Rep (j,0,m) printf ("%d", dp[x][j]); enter; //printf ("#%d%d\n", x,dp[x][0]); }}intMain () {n= Read (), M =read (); Rep (I,1, n) w[i] =read (); Rep (I,1, n) v[i] =read (); Rep (I,1, N) {x=read (); if(X! =0) Add (i,x); } CNT= N,tot =ecnt; Rep (I,1, N)if(!Dfn[i]) Tarjan (i); Rebuild (); //Rep (i,tot+1,ecnt) printf ("%d%d\n", e[i].from,e[i].to);Dfs0,0); printf ("%d\n", dp[0][m]); return 0;}
HAOI2010 Software Installation