【刷题】HDU 4966 GGS-DDU
Problem Description
Do you think this is a strange problem name? That is because you don't know its full name---'Good Good Study and Day Day Up!". Very famous sentence! Isn't it?
Now "GGS-DDU" is lzqxh's target! He has N courses and every course is divided into a plurality of levels. Just like College English have Level 4 and Level 6.
To simplify the problem, we suppose that the i-th course has Levels from level 0 to level a[i]. And at the beginning, lzqxh is at Level 0 of every course. Because his target is "GGS-DDU", lzqxh wants to reach the highest Level of every course.
Fortunately, there are M tutorial classes. The i-th tutoial class requires that students must reach at least Level L1[i] of course c[i] before class begins. And after finishing the i-th tutorial class, the students will reach Level L2[i] of course d[i]. The i-th tutoial class costs lzqxh money[i].
For example, there is a tutorial class only students who reach at least Level 5 of "Tiyu" can apply. And after finishing this class, the student's "MeiShu" will reach Level 10 if his "MeiShu"'s Level is lower than 10. (Don't ask me why! Supernatural class!!!")
Now you task is to help lzqxh to compute the minimum cost!
Input
The input contains multiple test cases.
The first line of each case consists of two integers, N (N<=50) and M (M<=2000).
The following line contains N integers, representing a[1] to a[N]. The sum of a[1] to a[N] will not exceed 500.
The next M lines, each have five integers, indicating c[i], L1[i], d[i], L2[i] and money[i] (1<=c[i], d[i]<=N, 0<=L1[i]<=a[c[i]], 0<=L2[i]<=a[d[i]], money[i]<=1000) for the i-th tutorial class. The courses are numbered from 1 to N.
The input is terminated by N = M = 0.
Output
Output the minimum cost for achieving lzqxh's target in a line. If his target can't be achieved, just output -1.
Sample Input
3 4
3 3 1
1 0 2 3 10
2 1 1 2 10
1 2 3 1 10
3 1 1 3 10
0 0
Sample Output
40
Description(CHN)
有n種科目,每個科目有等級0~a[i]。開始時,每個科目都是0級。現(xiàn)在要選擇一些課程進(jìn)行學(xué)習(xí)使得每一個科目都達(dá)到最高等級。有m節(jié)課。對于每門課給出c1[i],L1[i],c2[i],L2[i],money[i],要選擇這門課要求科目c1[i]的等級不小于L1[i],可以使科目c2[i]的等級升為L2[i],花費金錢money[i]。請計算最小花費是多少。
Solution
最小樹形圖
每門科目每個等級都設(shè)為一個點
所有課都對應(yīng)一條權(quán)值為花費金錢的有向邊
然后對于每一門課,將它的每個等級都向低一級連一條 \(0\) 費的邊,那么只要到達(dá)高等級,低等級一定選到,并且不會影響最終代價
于是建個超級源點跑最小樹形圖就好了
轉(zhuǎn)載于:https://www.cnblogs.com/hongyj/p/9285748.html
總結(jié)
以上是生活随笔為你收集整理的【刷题】HDU 4966 GGS-DDU的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Collections和Collecti
- 下一篇: leetcode 103. 二叉树的锯齿