Expensive offer time limit: 1000 msmemory limit: 10000 kbthis problem will be judged on PKU. Original ID: 1062
64-bit integer Io format: % LLD Java class name: Main the young explorer came to an Indian tribe. There he fell in love with the daughter of the chief, so he went to ask for advice from the Chief. The chief promised to marry his daughter only when he used 10000 gold coins as a dowry. The explorer asked the chief to lower his requirements if he could not get so many gold coins. The chief said, "Well, if you can get me the high priest's leather jacket, I only need 8000 gold coins. If you can get his crystal ball, you only need 5000 gold coins. "The explorer ran to the high priest and asked him for a leather jacket or a crystal ball. The high priest asked him to exchange his gold coins or get something else for him. He could lower the price. As a result, the explorer ran to other places, and other people made similar requests, or directly exchanged gold coins, or found other things to lower the price. However, it is not necessary for the explorer to change things with a variety of things, because they will not get a lower price. The explorer now needs your help so that he can marry his sweetheart with the least gold coins. What he wants to tell you is that in this tribe, the hierarchy concept is very strict. Two people whose status gap exceeds a certain limit will not conduct any form of direct contact, including transactions. He is an outsider, so he is not subject to these restrictions. However, if he makes a transaction with a person with a lower position, the person with a higher position will not trade with him. They think that this is like indirect contact, and the opposite is true. Therefore, you need to provide him with the best solution after considering all the situations.
For convenience, we numbered all items from 1, and the promise of the chief is also considered as an item, and the number is always 1. Each item has a corresponding price P, owner's Position Level L, and a series of alternatives Ti and the corresponding "discount" vi. If the gap between the two positions exceeds m, it cannot be "indirect transaction ". Based on the data, you must calculate the minimum amount of gold coins required by the explorer to marry the daughter of the chief.
The first line of input is two integers, m, n (1 <= n <= 100), indicating the limit of the status level gap and the total number of items in turn. Next, the descriptions of N items are given in ascending order of numbers. The description of each item starts with three non-negative integers p, L, and x (x <n), indicating the price of the item, the owner's Position level, and the total number of substitutes. The next line in Line X contains two integers T and V, indicating the replacement number and "preferential price" respectively ". Outputs the minimum number of gold coins required. Sample Input
1 410000 3 22 80003 50001000 2 14 2003000 2 14 20050 2 0
Sample output
5250
Source Zhejiang problem solving: start point of the application enumeration of the shortest Circuit
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib>10 #include <string>11 #include <set>12 #include <stack>13 #define LL long long14 #define INF 0x3f3f3f3f15 #define pii pair<int,int>16 using namespace std;17 const int maxn = 110;18 struct arc{19 int to,cost,next;20 arc(int x = 0,int y = 0,int z = -1){21 to = x;22 cost = y;23 next = z;24 }25 };26 arc e[maxn*maxn];27 int head[maxn],d[maxn],lv[maxn];28 int N,M,P,L,X,T,V,tot;29 bool done[maxn];30 void add(int u,int v,int cost){31 e[tot] = arc(v,cost,head[u]);32 head[u] = tot++;33 }34 void dijkstra(int low,int high){35 for(int i = 0; i <= N; ++i){36 d[i] = INF;37 done[i] = false;38 }39 d[0] = 0;40 priority_queue< pii,vector< pii >,greater< pii > >q;41 q.push(make_pair(0,0));42 while(!q.empty()){43 int u = q.top().second;44 q.pop();45 if(done[u]) continue;46 done[u] = true;47 for(int i = head[u]; ~i; i = e[i].next){48 if(lv[e[i].to] >= low && lv[e[i].to] <= high && d[e[i].to] > d[u] + e[i].cost){49 d[e[i].to] = d[u] + e[i].cost;50 q.push(make_pair(d[e[i].to],e[i].to));51 }52 }53 if(done[1]) return;54 }55 }56 int main(){57 while(~scanf("%d %d",&M,&N)){58 memset(head,-1,sizeof(head));59 tot = 0;60 for(int i = 1; i <= N; ++i){61 scanf("%d %d %d",&P,&L,&X);62 add(0,i,P);63 lv[i] = L;64 while(X--){65 scanf("%d %d",&T,&V);66 add(T,i,V);67 }68 }69 int ans = INF;70 for(int i = lv[1] - M; i <= lv[1]; ++i){71 dijkstra(i,i+M);72 ans = min(ans,d[1]);73 }74 printf("%d\n",ans);75 }76 return 0;77 }View code
Poj 1062 expensive dowry