POJ-1062 expensive hiring interval Enumeration

Source: Internet
Author: User

For the second time, given a level limit of M, we can solve the problem by enumerating the position of the first vertex. The idea is clear.

For (INT I = 0; I <= m; ++ I) indicates the offset of the class of the first vertex within the m length range. then you can build an edge in the interval, Floyd.

The Code is as follows:

# Include <cstdlib> # include <cstdio> # include <cstring> # include <algorithm> # include <iostream> # define INF 0x3f3f3fusing namespace STD; int m, n, mey [105], LVL [105], head [105], idx; int lwall, rwall, G [105] [105]; struct edge {int V, Val, next;} e [10005]; // reserved replacement list void addedge (int x, int V, int Val) {++ idx; E [idx]. V = V, E [idx]. val = val; E [idx]. next = head [X], head [x] = idx;} inline bool in (int x) {I F (LVL [x]> = lwall & LVL [x] <= rwall) {return true;} else return false;} void build () {memset (G, 0x3f, sizeof (g); For (INT I = 1; I <= N; ++ I) {G [I] [I] = 0; for (Int J = head [I]; J! =-1; j = E [J]. next) {If (in (I) & in (E [J]. v) {G [I] [E [J]. v] = E [J]. val ;}}} void Floyd (Int & RET) {for (int K = 1; k <= N; ++ K) {for (INT I = 1; I <= N; ++ I) {for (Int J = 1; j <= N; ++ J) {If (G [I] [k]! =-1 & G [k] [J]! =-1) {// G [I] [J] = min (G [I] [J], G [I] [k] + G [k] [J]) ;}}}for (INT I = 1; I <= N; ++ I) {If (G [1] [I]! = Inf) {ret = min (Ret, G [1] [I] + mey [I]) ;}} int main () {int C, V, Val, RET; while (scanf ("% d", & M, & n) = 2) {ret = inf; idx =-1; memset (Head, 0xff, sizeof (head); For (INT I = 1; I <= N; ++ I) {scanf ("% d", & mey [I], & LVL [I], & C); For (Int J = 1; j <= C; ++ J) {scanf ("% d", & V, & Val); addedge (I, V, Val) ;}// enumerate the leftmost and rightmost for (INT I = 0; I <= m; ++ I) {lwall = LVL [1]-I, rwall = lwall + m; If (lwall <0) break; // The left boundary cannot be a negative number. // confirm that the left and right boundary is building (); Floyd (RET);} printf ("% d \ n", RET );} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.