A-The expensive dowry
crawling in process ...
crawling failedTime
limit:MS
Memory Limit:10000KB
64bit IO Format: %I64D &%i64u SubmitStatus Practice POJ 1062Appoint Description:System Crawler (2016-05-06)
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 200#include <stdio.h> #include <vector> #include <algorithm> #include <string.h> #include < Math.h>using namespace Std;struct node{int price,level;} C[105];struct node1{int Num,discount;}; Vector<node1>edge[105];int n,m,result;bool vis[105];int dfs (int x,int sum,int max_level,int min_level) {result= Min (result,sum); Max_level=max (Max_level,c[x].level); Min_level=min (Min_level,c[x].level); for (int i=0;i<edge[x ].size (); i++) {Node1 temp=edge[x][i];if (fabs (min_level-c[temp.num].level) <=m&&fabs (max_level-c[ Temp.num].level) <=m&&!vis[temp.num] {Vis[temp.num]=true;dfs (Temp.num,sum+temp.discount+c[temp.num]). Price-c[x].price,max (Max_level,c[x].level), Min (min_level,c[x].level)); vis[temp.num]=false;}}} int main () {while (~SCANF ("%d%d", &m,&n)) {memset (vis,false,sizeof (Vis)); Memset (Edge,0,sizeof (Edge)); memset (&c,0,sizeof (&c)); for (int i=1;i<=n;i++) {int x;scanf ("%d%d%d", &c[i].price,&c[i].level,&x); for (int j=0;j<x;j++) {Node1TEMP;SCANF ("%d%d", &temp.num,&temp.discount); Edge[i].push_back (temp);}} Result=c[1].price;vis[1]=true;dfs (1,c[1].price,c[1].level,c[1].level);p rintf ("%d\n", result);} return 0;}
3000 2 14 20050 2 0
Sample Output
5250
Although I do not know the deep search why can not see the comment area that the data is too weak.
Everyone is using the Dijkstra algorithm ... All right
And there's a hard-to-understand part of the problem, and that's where I made the mistake. "If the difference in status between two people is more than M, you cannot" trade indirectly ".
I understand that if two people have a grade difference of more than M in the two-person transaction, you cannot trade with a person who knows that all trading members cannot exceed M ....
DFS AC code:
poj1062 expensive dowry (DFS)