zoukankan      html  css  js  c++  java
  • HDU 4044 GeoDefense

    GeoDefense

    Time Limit: 5000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 4044
    64-bit integer IO format: %I64d      Java class name: Main
    Tower 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. Many games, such as Flash Element Tower Defense, feature enemies that run through a "maze", which allows the player to strategically place towers for optimal effectiveness. 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 Without". 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 effectiveness so that the fortifications 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 effective and if the enemy is shot to death in your bases, you still win.
     

    Input

    The 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. 
     

    Output

    For each test case, output a line containing the highest HP value of your enemy that you can deal with. It means that if your enemy’s HP is larger than that highest value, you can’t guarantee your victory.
     

    Sample Input

    2
    2
    1 2
    30
    3 10 20 20 40 30 50
    3 10 30 20 40 30 45
    4
    2 1
    3 1
    1 4
    60
    3 10 20 20 40 30 50
    3 10 30 20 40 30 45
    3 10 30 20 40 30 35
    3 10 30 20 40 30 35

    Sample Output

    70
    80

    Source

     
    解题:树形背包
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1010;
     4 const int INF = 0x3f3f3f3f;
     5 using PII = pair<int,int>;
     6 vector<int>g[maxn];
     7 int dp[maxn][210],hp[maxn][210],n,m;
     8 void dfs(int u,int fa) {
     9     if(u > 1 && g[u].size() == 1) {
    10         for(int i = 0; i <= m; ++i)
    11             dp[u][i] = hp[u][i];
    12         return;
    13     }
    14     for(int i = g[u].size()-1; i >= 0; --i) {
    15         if(g[u][i] == fa) continue;
    16         dfs(g[u][i],u);
    17         for(int j = m; j >= 0; --j) {
    18             int tmp = 0;
    19             for(int k = 0; k <= j; ++k)
    20                 tmp = max(tmp,min(dp[u][j-k],dp[g[u][i]][k]));
    21             dp[u][j] = tmp;
    22         }
    23     }
    24     for(int j = m; j >= 0; --j)
    25         for(int k = 0; k <= j; ++k)
    26             dp[u][j] = max(dp[u][j],dp[u][j-k] + hp[u][k]);
    27 }
    28 int main() {
    29     int kase,u,v;
    30     scanf("%d",&kase);
    31     while(kase--) {
    32         scanf("%d",&n);
    33         for(int i = 0; i <= n; ++i) g[i].clear();
    34         memset(dp,0x3f,sizeof dp);
    35         memset(hp,0,sizeof hp);
    36         for(int i = 1; i < n; ++i) {
    37             scanf("%d%d",&u,&v);
    38             g[u].push_back(v);
    39             g[v].push_back(u);
    40         }
    41         scanf("%d",&m);
    42         for(int i = 1,t; i <= n; ++i) {
    43             scanf("%d",&t);
    44             while(t--) {
    45                 scanf("%d%d",&u,&v);
    46                 hp[i][u] = max(hp[i][u],v);
    47             }
    48             for(int j = 1; j <= m; ++j)
    49                 hp[i][j] = max(hp[i][j],hp[i][j-1]);
    50         }
    51         dfs(1,0);
    52         printf("%d
    ",dp[1][m]);
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    bzoj千题计划174:bzoj1800: [Ahoi2009]fly 飞行棋
    bzoj千题计划173:bzoj1257: [CQOI2007]余数之和sum
    bzoj千题计划172:bzoj1192: [HNOI2006]鬼谷子的钱袋
    bzoj千题计划171:bzoj2456: mode
    bzoj千题计划170:bzoj1968: [Ahoi2005]COMMON 约数研究
    bzoj千题计划169:bzoj2463: [中山市选2009]谁能赢呢?
    bzoj千题计划168:bzoj3513: [MUTC2013]idiots
    oracle 11g RAC 的一些基本概念(四)
    fdisk用法(转载)
    Oracle 11g 新特性 -- Oracle Restart 说明(转载)
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4944841.html
Copyright © 2011-2022 走看看