【刷题】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種科目,每個(gè)科目有等級(jí)0~a[i]。開始時(shí),每個(gè)科目都是0級(jí)?,F(xiàn)在要選擇一些課程進(jìn)行學(xué)習(xí)使得每一個(gè)科目都達(dá)到最高等級(jí)。有m節(jié)課。對(duì)于每門課給出c1[i],L1[i],c2[i],L2[i],money[i],要選擇這門課要求科目c1[i]的等級(jí)不小于L1[i],可以使科目c2[i]的等級(jí)升為L(zhǎng)2[i],花費(fèi)金錢money[i]。請(qǐng)計(jì)算最小花費(fèi)是多少。
Solution
最小樹形圖
每門科目每個(gè)等級(jí)都設(shè)為一個(gè)點(diǎn)
所有課都對(duì)應(yīng)一條權(quán)值為花費(fèi)金錢的有向邊
然后對(duì)于每一門課,將它的每個(gè)等級(jí)都向低一級(jí)連一條 \(0\) 費(fèi)的邊,那么只要到達(dá)高等級(jí),低等級(jí)一定選到,并且不會(huì)影響最終代價(jià)
于是建個(gè)超級(jí)源點(diǎn)跑最小樹形圖就好了
轉(zhuǎn)載于:https://www.cnblogs.com/hongyj/p/9285748.html
總結(jié)
以上是生活随笔為你收集整理的【刷题】HDU 4966 GGS-DDU的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Collections和Collecti
- 下一篇: 1.搭建JavaEE开发环境