I can't say anything about this question. I have been crazy about it for a long time. Now I am finally AC. I have spent too much time on this question ,,,,
When I first read this question, I thought of using DFS. Later I remembered that I had read the * algorithm the day before yesterday. It is written using the * algorithm.
[Html]
# Include <stdio. h>
# Include <math. h>
Int map [301] [301]; // record edge
Int di [301], val [301]; // record status, Value
Struct list
{
Int;
Int max;
Int min;
Int v;
} Open [301], close [301], ex; // open is the starting array, and close is the result array.
Int open_n = 0;
Int close_n = 0;
Int cheak [301] [301];
Int m, n;
Void guanlian ()
{
Int open_first, I, j, open_val, open_max, open_min;
Open_first = open [open_n-1]. ;//------------------------------------------------
Open_val = open [open_n-1]. v;
Open_max = open [open_n-1]. max;
Open_min = open [open_n-1]. min; // The middle part is to transfer the smallest value in the open array to the close array
Open_n --;
Close [close_n] = open [open_n];
Close_n ++ ;//-------------------------------------------------
For (I = 1; I <= n; I ++)
{
If (map [open_first] [I]! =-1 & cheak [open_first] [I])
{
If (fabs (di [I]-open_max) <= m) & fabs (di [I]-open_min) <= m)
{
If (di [I] <open_min )//-------------------------------------------
{
Open [open_n]. min = di [I];
Open [open_n]. max = open_max;
}
Else if (di [I]> open_max) // This part determines the maximum and minimum position of the person involved in the redemption chain.
{
Open [open_n]. max = di [I];
Open [open_n]. min = open_min;
}
Else //----------------------------------------------
{
Open [open_n]. max = open_max;
Open [open_n]. min = open_min;
}
Cheak [open_first] [I] = 0;
Open [open_n]. a = I;
Open [open_n]. v = map [open_first] [I] + open_val;
Open_n ++;
}
}
}
For (I = 0; I <open_n; I ++) // sorts open arrays by value.
{
For (j = I + 1; j <open_n; j ++)
{
If (open [I]. v + val [open [I]. a]) <(open [j]. v + val [open [j]. a])
{
Ex = open [I];
Open [I] = open [j];
Open [j] = ex;
}
}
}
}
Int ()
{
Int I, nmax, max;
Open [0]. a = 1;
Open [0]. v = 0;
Open [0]. max = di [1];
Open [0]. min = di [1];
Open_n ++;
While (open_n! = 0)
{
Guanlian ();
}
Nmax = val [1];
For (I = 0; I <close_n; I ++) // find the smallest value in the close array, that is, the result value.
{
Max = close [I]. v + val [close [I]. a];
If (max <nmax)
{
Nmax = max;
}
}
Return nmax;
}
Int main ()
{
Int I, j, p, l, x, t, v, val_put;
For (I = 1; I <= 300; I ++)
{
Close [I]. v = 0;
}
For (I = 1; I <= 300; I ++)
{
For (j = 1; j <= 300; j ++)
{
Cheak [I] [j] = 1;
Map [I] [j] =-1;
}
}
Scanf ("% d", & m, & n );
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & p, & l, & x );
Di [I] = l; val [I] = p;
For (j = 1; j <= x; j ++)
{
Scanf ("% d", & t, & v );
Map [I] [t] = v;
}
}
Val_put = ();
Printf ("% d \ n", val_put );
Return 0;
}
Author: rowanhaoa