HDU 1011 Starship Troopers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.