Geodefensetime limit: 12000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 663 accepted submission (s): 267
Problem descriptiontower defense is a kind of real-time strategy computer games. the goal of tower Defense Games is to try to stop enemies from reaching your bases by building towers which shoot at them as they pass.
The choice and positioning of the towers is the essential strategy of the game. when games, such as flash element tower defense, feature enemies that run through a "Maze", which allows the player to strategically place towers for optimal upgrade tiveness. however, some versions of the genre force the user to create the maze out of their own towers, such as desktop tower defense. some versions are a hybrid of these two types, with preset paths that can be modified to some extent by tower placement, or towers that can be modified by Path Placement.
Geodefense is a thinking man's action tower defense. it has become one of "PC world's 10 iPhone games you cannot live ". using exciting vectorized graphics, this highly kinetic game brings a whole new dimension to the defense genre. devastate creeps with blasters, lasers and missiles and watch their energy debris swirl through the gravity wells of your vortex towers.
There is a geodefense maze of N points numbered from 1 and connected by passageways. there are at least two dead ends among these N points, and there is always one and only one path between any pair of points. point 1 is a dead end, and it's the base of enemies, and all the other dead ends are your bases.
To prevent the enemy reaching your bases, You have to construct towers to attack the enemy. you can build tower on any point and you can only build one tower on one point. A tower can only shot the enemy when it passes the tower. you are given Ki choices to build tower on point I, and each choice is given in the format of (price, power) which means that you can build a tower with attack power value equals power in the cost of price. you can also build nothing on a point so it will not cost your money. A tower will reduce the enemy's HP by its attack power. when the HP is less or equal to zero, the enemy dies immediately.
The base of enemies will release only one enemy. it moves very fast that you cannot do anything such as building towers while it is running. it runs all the way until it dies or reaches one of your bases. however, you cannot predict the route it will go through. to win the game, you must kill the enemy before it reaches your bases. you have to strategically place towers for optimal upgrade tiveness so that the forications ications are steady enough to protect the bold and powerful enemy with high HP. you are troubling your head on figuring out the highest HP of the enemy you are able to kill on the way certainly. you have money m when the game begins.
Please note that the towers build in the enemy's base or your bases are all valid tive and if the enemy is shot to death in your bases, you still win.
Inputthe input consists of several test cases. The first line is an integer T (1 <=t <= 20), which shows the number of the cases.
For each test case, the first line contains only one integer N (2 <= n <= 1000) Meaning the number of points.
The following n-1 lines describe the passageways. Each line contains two integers U and V, which are the endpoints of a passageway.
The following line contains only one integer m (1 <= m <= 200) Meaning the amount of your money when the game begins.
Then n lines follow. the ith line describes the construction choices of the ith point. it starts with an integer KI (0 <= Ki <= 50) and Ki is followed by Ki pairs of integers separated by spaces. the jth pair is (pricei, J, poweri, J), 0 <= pricei, j <= 200, 0 <= poweri, j <= 50000. ki being zero means that you can't build a tower on the ith point.
Outputfor each test case, output a line containing the highest HP value of your enemy that you can deal. it means that if your enemy's HP is larger than that highest value, you can't guarantee your vicur.
Sample Input
221 2303 10 20 20 40 30 503 10 30 20 40 30 4542 13 11 4603 10 20 20 40 30 503 10 30 20 40 30 453 10 30 20 40 30 353 10 30 20 40 30 35
Sample output
7080
Sourcethe 36th ACM/ICPC Asia Regional Beijing site -- online contest
(Copy from others) This is a tower defense game, and the map is a map of N numbers as 1 ~ Node 1 is the enemy base, and other leaf nodes are your base. The enemy's base will continuously generate monsters. To prevent the enemy from attacking your base, you can choose to build a tower. Each node can only create one tower, and node I can have one Ki Tower for you to choose from. The price and attack power are price_ I, power_ I, and the attack power is power_ I, the effect is to reduce the Power Point of the enemy's blood when the enemy passes through this node. From the enemy base to any of your leaf base paths, the sum of attack power of all the towers in this path is the base's resistance. The attack path of the enemy is uncertain. To protect all your bases, you must determine the one with the lowest resistance among all the bases. You only have m money. Ask the best solution, what is the maximum blood volume that can resist the enemy? That is to say, what is the maximum value of making all the leaf bases have the lowest resistance?
Train of Thought: tree-like DP, DP [u] [J] indicates the maximum attack power at the U point, and J is allocated to the child, taking the child's minimum value, take the maximum value of the allocation scheme, because each point can be built with a tower, so after updating the tree structure, DP [u] [J] is updated, and then 01 is used to update the column in the backpack, note that the price can be 0, that is, it has been known for a long time. Decline ~
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <map> # include <stack> # include <vector> # include <set> # include <queue> # include <sstream> # define maxn 1005 # define maxn 100005 # define mod 100000000 # define INF 0x3f3f3f # define PI ACOs (-1.0) # define EPS 1e-8typedef long ll; using namespace STD; int n, m, ANS, CNT, TOT, flag; int DP [maxn] [205], head [maxn]; int num [maxn], cost [maxn] [55], Val [maxn] [55]; struct node {int V, W, next;} edge [10005]; void addedge (int u, int V, int W) {CNT ++; edge [CNT]. V = V; edge [CNT]. W = W; edge [CNT]. next = head [u]; head [u] = CNT;} void DFS (int u, int FA) {DP [u] [0] = inf; int I, j, k, V, t; for (I = head [u]; I; I = edge [I]. next) {v = edge [I]. v; If (V = FA) continue; DFS (v, U); For (j = m; j> = 0; j --) {T = 0; for (k = 0; k <= J; k ++) {T = max (T, min (DP [v] [K], DP [u] [J-K]);} DP [u] [J] = T;} If (DP [u] [0] = inf) DP [u] [0] = 0; // you must add this judgment for (j = m; j> = 0; j --) {T = DP [u] [J]; for (I = 1; I <= num [u]; I ++) {If (j> = cost [u] [I]) {T = max (t, DP [u] [J-cost [u] [I] + val [u] [I]) ;}} DP [u] [J] = T ;}} int main () {int I, j, T; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); int U, V; CNT = 0; memset (Head, 0, sizeof (head); for (I = 1; I <n; I ++) {scanf ("% d", & U, & V); addedge (u, v, 0); addedge (v, U, 0 );} scanf ("% d", & M); for (I = 1; I <= N; I ++) {scanf ("% d ", & num [I]); For (j = 1; j <= num [I]; j ++) {scanf ("% d ", & cost [I] [J], & Val [I] [J]) ;}} memset (DP, 0, sizeof (DP); DFS (1, 0 ); printf ("% d \ n", DP [1] [m]);} return 0 ;} /* 2042 13 11 43001 10 301 121 20 391 21 41 31 31 53 63 85 91002 50 40 20 301 10 201 30 151 201 10 111 20 1001 10 1001 10 801 10 1031 5 22 3301 10 201 10 201 10 20 */