Buy or Build Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1360 Accepted: 539
Description
World Wide Networks (WWN) is a leading company that operates large telecommunication networks. WWN would like to setup a new network in Borduria, a nice country that recently managed to get rid of its military dictator Kurvi-Tasch and which is now seeking for investments of international companies (for a complete description of Borduria, have a look to the following Tintin albums ``King Ottokar's Sceptre, ``The Calculus Affair and ``Tintin and the Picaros). You are requested to help WWN todecide how to setup its network for a minimal total cost.Input
The first line contains the number n of cities in the country ( 1<=n<=1000 ) followed by the number q of existing subnetworks ( 0<=q<=8 ). Cities are identified by a unique integer value ranging from 1 to n . The first line is followed by q lines (one per subnetwork), all of them following the same pattern: The first integer is the number of cities in the subnetwork. The second integer is the the cost of the subnetwork (not greater than 2 x 106 ). The remaining integers on the line (as many as the number of cities in the subnetwork) are the identifiers of the cities in the subnetwork. The last part of the file contains n lines that provide the coordinates of the cities (city 1 on the first line, city 2 on the second one, etc). Each line is made of 2 integer values (ranging from 0 to 3000) corresponding to the integer coordinates of the city.Output
Your program has to write the optimal total cost to interconnect all cities.Sample Input
7 3 2 4 1 2 3 3 3 6 7 3 9 2 4 5 0 2 4 0 2 0 4 2 1 3 0 5 4 4
Sample Output
17
Hint
Sample Explanation: The above instance is shown in Figure 2. An optimal solution is described in Figure 3 (thick edges come from an existing network while thin edges have been setup from scratch).Source
Southwestern Europe 2005
#include#include #include #include #include #include const int N=1009; using namespace std; int fa[N]; int n,q; int cost[N]; int m[N]; int f[N][N]; int x[N],y[N]; int cnt; struct Node { int a,b,len; bool operator<(const Node &a)const { return len>j)&1)) continue; num+=cost[j];//該方案費用已固定 for(int k=1;k