POJ 1062
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 39437 |
|
Accepted: 11432 |
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
For the path from the U point to the W point, he will trade with many levels of people, but must meet the points in the path, such as the difference is not more than a M value, then how to solve this problem? I was puzzled before I read the report!
Assuming that the path is appended with an additional condition, the situation may change, requiring that all points in the shortest circuit be ranked in a range [A, a], and if the interval is given well, simply filter the points in the graph.
The determination of this interval is obviously not random, then according to certain conditions, from the test instructions we know, the last of all the shortest points will be collected in the 1th point, that is, the point 1th is all the shortest points exist, well, this condition is very important, so that we can follow the number 1th point to a given interval, For example, the 1th point level is Lev, which means that all the shortest points must be satisfied within the [Lev-m,lev+m] range. Well, maybe you'll be eager to take this interval as the final interval, thinking that if the difference between the two points that appear within this interval exceeds the M value (which is present), it is clear that the test instructions is not met, so the interval continues to shrink. In fact, just a little bit of brain, you can find such an interval [lev-m,lev],[lev-m+1,lev+1],... ..., [Lev,lev+m], the first of these intervals to meet the conditions of the large interval, and if one of these intervals as a filter condition, The rank of any two points within this interval will not exceed the M value, which is a very special place (GO)
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4 Const intinf=99999999;5 intmaps[ the][ the],v[ the],d[ the],n;6 intl[ the],p[ the],inch[ the];7 8 intDijkstra ()9 {Tenmemset (V,0,sizeof(v)); One intI,j,k,mini; A - for(i=1; i<=n;i++) -d[i]=INF; thed[1]=0; - for(i=1; i<=n;i++) - { -mini=inf;k=-1; + for(j=1; j<=n;j++) - { + if(!v[j] &&inch[j] && d[j]<Mini) Amini=d[k=j]; at } - if(mini==INF) - Break; - -v[k]=1; - for(j=1; j<=n;j++) in { - if(!v[j] &&inch[j] && d[k]+maps[k][j]<D[j]) to { +d[j]=d[k]+Maps[k][j]; - } the } * } $Mini=INF;Panax Notoginseng for(i=1; i<=n;i++) - { the if(D[i]+p[i]<mini &&V[i]) +mini=d[i]+P[i]; A } the returnMini; + } - $ intMain () $ { - intm,x,t,v; - intI,j,minicost; the while(SCANF ("%d%d", &m,&n)! =EOF) - {Wuyi the for(i=1; i<=n;i++) - { Wu for(j=1; j<=n;j++) - { AboutMaps[i][j]= (i==j?0: INF); $ } - } - for(i=1; i<=n;i++) - { Ascanf" %d%d%d",&p[i],&l[i],&x); + for(j=1; j<=x;j++) the { -scanf"%d%d",&t,&V); $ if(maps[i][t]>V) the { themaps[i][t]=V; the } the } - } in intlev=l[1],coc; theminicost=INF; the for(i=0; i<=m;i++) About { theMemsetinch,0,sizeof(inch)); the for(j=1; j<=n;j++) the { + if(l[1]-M+I<=L[J] && l[j]<=l[1]+i) - inch[j]=1; the }BayiCoc=Dijkstra (); the if(coc<minicost) theminicost=coc; - } -printf"%d\n", minicost); the } the return 0; the}
View Code
The expensive dowry Dijkstra method