The expensive dowry
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 38474 |
|
Accepted: 11132 |
Description
The young explorers came to an Indian tribe. There he fell in love with the chief's daughter, so he went to Qiuqin to the chief. The chief asked him to use 10,000 gold coins as a dowry to promise to marry his daughter. The explorers could not get so many gold coins that they asked the chief to lower their demands. The sheikh said, "Well, if you can get me the piao of the high priest, I can just have 8000 gold." If you can get his crystal ball, then just 5000 gold. The explorer ran to the high priest and demanded Piao or a crystal ball, and the high priest asked him to change it with gold coins, or to get other things for him, he could lower the price. The explorers then ran to other places, and others made similar demands, either by exchanging coins directly or by finding something else to lower the price. But there's no need for explorers to change things with a variety of things, because they won't get a lower price. Explorers now need your help so that he can marry his sweetheart with the least amount of gold. And what he's going to tell you is that in this tribe, hierarchy is very strong. No direct contact will be made between two persons with a status gap exceeding a certain limit, including transactions. He is a foreigner, so he can not be subject to these restrictions. But if he trades with a lower-level person, the higher-status person will not trade with him, they think it is indirect contact and vice versa. So you need to give him the best plan after considering all the circumstances.
For the sake of convenience, we numbered all items starting from 1, and the chief's promise was also regarded as an item, and the number was always 1. Each item has a corresponding price p, the host's status level L, as well as a series of alternatives ti and the replacement of the corresponding "preferential" Vi. If the difference in status between the two people exceeds m, it cannot be "indirectly traded". You have to figure out how much gold the adventurer needs at least to marry the chief's daughter.
Input
The input first line is two integers m,n (1 <= N <= 100), which in turn represents the status level gap limit and the total number of items. Next, according to the number from small to large in order to give a description of n items. The description of each item begins with three nonnegative integers p, L, X (x < N), which in turn indicate the price of the item, the rank of the host, and the total number of substitutes. The next x row contains two integers t and V, each representing the replacement number and the "preferential price".
Output
Output the minimum number of coins required.
Sample Input
1 410000 3 22 80003 50001000 2 14 2003000 2 14 20050 2 0
Sample Output
5250
This problem really makes my egg ache. I began to use the record path, found no solution, engage in a day, and then Baidu a puzzle. Find yourself akzent stupid, stupid home, as long as the choice of status interval size m of the interval, and then Dijkstra to find a single source of the shortest path does not solve it, of course, it is important to note that the zone must include the status of the Chiefs of the value. The code is followed by test data.
Look at the code:
#include <stdio.h> #include <string.h> #include <stdlib.h> #define INF 100000000#define MAX 110int Graph[max][max], Map[max][max], Level[max], dis[max];bool visited[max];int dijsktra (int n) {memset (Visited,false, sizeof (visited)); for (int i = 1; I <= n; ++i) {dis[i] = map[1][i];} DIS[1] = map[1][1]; int ans = dis[1]; visited[1] = true; for (int i = 0; i < n; ++i) {int min = INF, index = 0; T j = 1; J <= N; ++J) {if (!visited[j] && min>dis[j]) {min = Dis[j];index = j;}} if (min = = INF) {break;} Visited[index] = true; for (int j = 1; j <= N; ++j) {if (map[index][j] = = INF) {continue;} if (Dis[j] > Dis[index] + map[index][j]) {dis[j] = Dis[index] + map[index][j];}} Dis[index] + = Map[index][index];ans = Ans>dis[index]?dis[index]:ans;} return ans;} void init (int n) {for (int i = 0, I <= N; ++i) {for (int j = 0; J <= i; ++j) {map[i][j] = map[j][i] = INF;}} int main () {int m, n; while (scanf ("%d%d", &m,&n)! = EOF) {for (int i = 0; I < = N; ++i) {for (int j = 0; J <= i; ++j) {graph[i][j] = graph[j][i] = INF;}} for (int i = 1; I <= n; ++i) {int p,x;scanf ("%d%d%d", &p,&level[i],&x); graph[i][i] = p; for (int j = 1; J & Lt;= x; ++J) {int T, V; scanf ("%d%d", &t,&v); graph[i][t] = v;}} int left=level[1]-m>0?level[1]-m:0, Right=left+m;int k = left, ans = INF, while (K<=level[1]) {init (n); for (int i = 1; I <= N; ++i) {if (Level[i]>=left && level[i]<=right) {for (int j = 1; j <= N; ++j) {map[i][j] = Graph[i][j];}} left++, right++; int num = Dijsktra (n); ans = Ans>num?num:ans; ++k;} printf ("%d\n", ans);} return 0;} /* Test Data 1:1 410000 3 22 80003 50001000 2 14 2003000 2 14 20050 2 05250 test data 2:1 510000 3 42 30003 20004 20005 90008000 2 33 50 004 20005 70005000 1 02000 4 15 190050 1 04000 test data 3:3 810000 3 62 30003 20004 20005 90007 10008 50088000 2 33 50004 20005 70005000 1 16 10002000 4 15 190050 1 05000 1 17 40072000 4 15 190080 3 02950 test data 4:1 101324 0 01234 0 0255 0 067 0 056 002134 0 0456 0 02345 0 067 0 06436 0 01324 test Data 5:1 410000 3 22 13 31000 2 24 13 11000 3 14 2100 4 0105 test data 6:3 510000 3 42 3 0003 20004 20005 90008000 2 33 50004 20005 70005000 1 02000 4 15 190050 1 03950 test Data 7:0 510000 3 42 30003 20004 20005 90008000 2 33 50004 20005 70005000 4 02000 3 15 190050 2 04000*/
With June
POJ 1062 expensive dowry Dijkstra algorithm, medium difficulty,,, together let me tired of not love the topic