HDU 2415 bribing FIPA

Source: Internet
Author: User

Bribing Fipatime limit:1000msmemory limit:32768kbthis problem would be judged onHDU. Original id:2415
64-bit integer IO format: %i64d Java class name: Main  there is going to being a voting at FIPA (Fédération Internationale de Programmation Association) to determine the host Of the next IPWC (International Programming World Cup). Benjamin Bennett, the delegation of Diamondland to FIPA, was trying to seek other delegation's support for a vote in favor of hosting iwpc in Diamondland. Ben is trying to buy the votes by Diamond gifts. He has figured out the voting price of each and every country. However, he knows that there was no need to diamond-bribe every country, since there was small poor countries that take vot E orders from their respected superpowers. So, if you bribe a country, you had gained the vote of any other country under its domination (both directly and via othe R countries domination). For example, if C are under domination of B, and B is under domination of A, one could get the vote of all three countries Ju St by bribing A. Note that no country are under domination of more than one country, and the domination relationship makes No cycle. You is to help him, against a big diamond, by writing a program to find out the minimum number of diamonds needed th At-least m countries vote in favor of Diamondland. Since Diamondland is a candidate, it stands out of the voting process.
InputThe input consists of multiple test cases. Each test case starts with a line containing the integers n (1≤n≤200) and M (0≤m≤n) which is the number of countr IES participating in the voting process, and the number of votes Diamondland needs. The next n lines, each describing one country, is of the following form:

countryname diamondcount DCName1 DCName1 ...

CountryNameThe name of the country, is a string of at least one and at most letters and Diamondcountis a positive integer which are the number of diamonds needed to get the vote of this country and all of the countries that Their names come in the list DCName1 DCName1Which means they is under direct domination of that country. Note that it was possible that some countries does not has any other country under domination. The end of the input is marked by a and containing a single # character.

OutputFor each test case, write a single line containing a number showing the minimum number of diamonds needed to gain the vote Of at least m countries.
Sample Input
3 2Aland 10Boland Alandcoland 15#
Sample Output
20
Source2006 Asia Regional Tehran Problem solving: tree-shaped DP
1#include <bits/stdc++.h>2 using namespacestd;3 Const intINF =0x3f3f3f3f;4 Const intMAXN = -;5unordered_map<string,int>UMP;6vector<int>G[MAXN];7 intN,M,W[MAXN],SON[MAXN],DP[MAXN][MAXN];8 BOOL inch[MAXN];9 voidDfsintu) {Tendp[u][0] =0; OneSon[u] =1; A      for(inti = g[u].size ()-1; I >=0; --i) { - DFS (G[u][i]); -Son[u] + =Son[g[u][i]]; the          for(intj = Son[u]; J >=0; --j) -              for(intK =0; K <= J && K <= Son[g[u][i]; ++k) -Dp[u][j] = min (Dp[u][j],dp[u][j-k] +dp[g[u][i]][k]); -     } +Dp[u][son[u]] =min (dp[u][son[u]],w[u]); - } + intMain () { A     Charstr[ $]; at     intID =1, tmp,u,v; -      while(Gets (str) && str[0] !='#'){ - ump.clear (); -Memsetinch,false,sizeof inch); -          for(inti =0; i < MAXN; ++i) g[i].clear (); -SSCANF (str,"%d%d",&n,&m); in          for(inti = id =1; I <= N; ++i) { -scanf"%s%d",str,&tmp); to             if(! (U = ump[str])) U = ump[str] = id++; +W[u] =tmp; -              while(GetChar ()! ='\ n'){ thescanf"%s", str); *                 if(! (v = ump[str])) v = ump[str] = id++; $                 inch[V] =true;Panax Notoginseng G[u].push_back (v); -             } the         } +w[0] =INF; A          for(inti =1; I < ID; ++i) the             if(!inch[i]) g[0].push_back (i); +Memset (DP,0x3f,sizeofDP); -Dfs0); $         intRET =INF; $          for(inti = m; I <= N; ++i) -ret = min (ret,dp[0][i]); -printf"%d\n", ret); the     } -     return 0;Wuyi}
View Code

HDU 2415 bribing FIPA

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.