Main topic:
Galaxy team to destroy some insects, the base of the worm is built in the ground. The base of the worm is composed of many rooms and tunnels. There are some insects and their chiefs in each room. Your mission is to destroy the entire base and capture as many chiefs as possible. Kill the worm and don't catch the leader easily. Members of the squad will not enter the room they have entered before. A ship can kill 20 worms. The rest can only be solved by the nerve gas to solve the remaining worms. Input data: The input n,m represents the number of insect chambers and the number of Starfleet fleets, followed by n lines, each line containing two integers, representing the number of bugs in each room and the number of chiefs. The next n-1 lines represent the number of tunnels respectively. Output: Maximum number of captures ==================================================================================================== ===============
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<queue>#include<vector>#include<map>using namespaceStd;typedefLong LongLL;Const intINF = 1e9+7;Const intMAXN = the;Const intMOD = 1e9+7;intDP[MAXN][MAXN], N, m;///the maximum number of kills that the nth room spends m can getintCOST[MAXN], VALUE[MAXN];BOOLVis[maxn];vector<vector<int> >G;voidDFS (intRootintm) {Vis[root]=true; intLen =g[root].size (); if(len = =1&& vis[g[root][0]] && cost[root] = =0) {dp[root][1] =Value[root]; return ; } for(intI=cost[root]; i<=m; i++) Dp[root][i]=Value[root]; for(intI=0; i<len; i++) { intv =G[root][i]; if(Vis[v] | | m-cost[root] <=0)Continue; DFS (V, M-Cost[root]); for(intj=m-1; j>=cost[root]; j--)///The number of soldiers left at the root . { for(intk=1; k<=m-j; k++)///number of nodes allocated to the son .Dp[root][j+k] = max (Dp[root][j+k], dp[root][j] +Dp[v][k]); } }}intMain () { while(SCANF ("%d%d", &n, &m), n+m!=-2) {g.clear (); G.resize (n+2); memset (Vis,false,sizeof(VIS)); Memset (DP,0,sizeof(DP)); for(intI=1; i<=n; i++) {scanf ("%d%d", &cost[i], &Value[i]); Cost[i]= (Cost[i] + +) / -; } for(intI=1; i<n; i++) { intA, B; scanf ("%d%d", &a, &b); G[a].push_back (b); G[b].push_back (a); } if(m) DFS (1, M); intAns =0; for(intI=0; i<=m; i++) ans= Max (ans, dp[1][i]); printf ("%d\n", ans); } return 0;}
HDU 1011 Starship Troopers