Devil CityTime limit (Common/Java): 1000 ms/3000 Ms running memory limit: 65536 Kbyte
Total submissions: 137 pass the test: 37
Description
God needs to create a warrior to destroy Satan. This warrior must pass through the devil's city to fight with Satan. There are m streets connecting N intersections (ranging from 1 to n) in the evil magic city. Every street is one-way (that is, you cannot go in the direction specified by the street ), in addition, it is impossible to go back to the original place no matter how you go in the city. At the beginning, the warrior's vitality (HP) was inithp, standing at the 1th intersection, while Satan waited for him at the nth intersection. There are many demons in every street, but some streets have been occupied by angels sent by God. When a warrior passes through the street connecting No. I to intersection J, if the demon occupies the street, his hp doubles and then decreases L [I, j], we record it as a [I, j] =-L [I, j]. If the angel occupies the street, his HP will first double and then add L [I, j], which is recorded as a [I, j] = + L [I, j]. If the street does not exist, a [I, j] = 0. If a warrior's HP <= 0 at a certain time point, it will die. This warrior will be very invincible. When he sees Satan, as long as he is still alive, he will be able to destroy Satan in one breath, so God does not want his inithp to be too high.
Task:
Given n, a [1. N, 1. N], find the smallest inithp so that the warrior can live to see Satan.
Input
The first line of the file has a positive integer N (3 ≤ n ≤ 100), followed by the number of J in line I is a [I, j] (the absolute value must not exceed an integer of 10000 ).
Output
Output the smallest inithp.
Sample Input
4
0-4 0-10
0 0 3 0
0 0 0-14
0 0 0 0
Sample output
4
Question Source
Oibh noip simulation Competition
# Include <iostream> <br/> using namespace STD; </P> <p> int N; <br/> int map [101] [101]; <br/> bool used [101]; <br/> int HP; <br/> bool flag; <br/> int ans; <br/> void DFS (INT now) <br/>{< br/> int I, temp; <br/> If (flag = false) <br/> for (I = 1; I <= N; I ++) <br/> If (used [I] = false & map [now] [I]! = 0) <br/>{< br/> used [I] = true; <br/> temp = hp; <br/> HP = (HP * 2 + map [now] [I]); <br/> If (HP >=10000) <br/> flag = true; <br/> else if (I! = N & HP> 0) <br/> DFS (I); <br/> else if (I = N & HP> 0) <br/> flag = true; <br/> HP = temp; <br/> used [I] = false; <br/>}</P> <p> void solve () <br/>{< br/> int mid, low = 1, top = 10000; <br/> for (; top> = low;) <br/>{< br/> mid = int (top + low)/2 ); <br/> HP = mid; <br/> flag = false; <br/> memset (used, false, sizeof (used )); <br/> DFS (1); <br/> If (flag = true) <br/>{< br/> ans = mid; <br/> Top = mid-1; <br/>}< br/> else low = Mid + 1; <br/>}< br/> int main () <br/>{< br/> memset (MAP, 0, sizeof (MAP )); <br/> CIN> N; <br/> int I, j; <br/> for (I = 1; I <= N; I ++) <br/> for (j = 1; j <= N; j ++) <br/> CIN> map [I] [J]; <br/> solve (); <br/> cout <ans <Endl; <br/> return 0; <br/>}< br/>