GGS-DDU

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1021    Accepted Submission(s): 504

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
 
Author
SYSU
 
Source
 
 
把没门课分成1 - a[i] 个等级  每个等级i都向i - 1 连一条边 表示 如果 当前达到了等级i  则 1 - (i - 1) 都相当于达到了
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int ID[maxn], IN[maxn], vis[maxn], pre[maxn];
int cnt; struct node
{
int u, v, c;
}Node[maxn*]; void add(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt++].c = c; } int dirmst(int root, int n, int m)
{
int ans = ;
while(true)
{
for(int i=; i<n; i++) IN[i] = INF; //记录最小前驱边的值 //1、找最小前驱边
for(int i=; i<m; i++)
{
int u = Node[i].u;
int v = Node[i].v;
if(Node[i].c < IN[v] && u != v)
{
pre[v] = u;
IN[v] = Node[i].c;
// cout<< e.v << " " << e.u <<endl;
}
} //2、判断是否联通
for(int i=; i<n; i++)
{
if(i == root) continue;
if(IN[i] == INF) return -;
} //3、找环
int cntnode = ;
mem(ID, -);
mem(vis, -);
IN[root] = ;
for(int i=; i<n; i++)
{
ans += IN[i];
int v = i;
while(vis[v] != i && ID[v] == - && v != root)
{
vis[v] = i;
v = pre[v];
}
//如果存在环 则把环中的点缩为一个点
if(v != root && ID[v] == -)
{
for(int j=pre[v]; j!=v; j=pre[j])
{
ID[j] = cntnode;
}
ID[v] = cntnode++;
}
}
if(cntnode == ) break; //没有环就结束 //重新标记其它点
for(int i=; i<n; i++)
if(ID[i] == -)
ID[i] = cntnode++;
for(int i=; i<m; i++)
{
int v = Node[i].v;
Node[i].u = ID[Node[i].u];
Node[i].v = ID[Node[i].v];
if(Node[i].u != Node[i].v)
Node[i].c -= IN[v];
}
n = cntnode;
root = ID[root];
}
return ans; } int sum[maxn], a[maxn], d, c, L1, L2;
int w, s; int main()
{
int n, m;
while(scanf("%d%d", &n, &m) != EOF)
{
if(n == && m == ) break;
mem(sum, );
cnt = ;
for(int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
a[i]++;
sum[i] = sum[i - ] + a[i];
}
for(int i = ; i <= m; i++)
{
//cin >> c >> L1 >> d >> L2 >> w;
scanf("%d%d%d%d%d", &c, &L1, &d, &L2, &w);
L1++, L2++;
add(sum[c - ] + L1, sum[d - ] + L2, w);
}
s = ;
for(int i = ; i <= n; i++)
{
add(s, sum[i - ] + , );
for(int j = a[i]; j >= ; j--)
add(sum[i - ] + j, sum[i - ] + j - , );
}
int ans = dirmst(s, sum[n] + , cnt);
if(ans < )
printf("-1\n");
else
printf("%d\n", ans); } return ;
}
 

GGS-DDU

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1021    Accepted Submission(s): 504

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
 
Author
SYSU
 
Source
 

GGS-DDU HDU - 4966的更多相关文章

  1. hdu 4966 GGS-DDU (最小树形图)

    比较好的讲解:http://blog.csdn.net/wsniyufang/article/details/6747392 view code//首先为除根之外的每个点选定一条入边,这条入边一定要是 ...

  2. HDU 4966 GGS-DDU(最小树形图)

    n个技能,每个技能有0-a[i]的等级,m个课程,每个课程需要前置技能c[i]至少达到lv1[i]等级,效果是技能d[i]达到lv2[i]等级,花费w[i]. 输出最小花费使得全技能满级(初始全技能0 ...

  3. 【刷题】HDU 4966 GGS-DDU

    Problem Description Do you think this is a strange problem name? That is because you don't know its ...

  4. hdu 4966 最小树形图

    将每门课等级拆成0,1,2,3...a[i]个点,对每一个等级大于0的点向它低一级连边,权值为0[意思是,若修了level k.则level(0~k)都当做修了] 将输入的边建边,权值为money[i ...

  5. hdu 4960 Another OCD Patient (最短路 解法

    http://acm.hdu.edu.cn/showproblem.php?pid=4960 2014 Multi-University Training Contest 9 Another OCD ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. 《React Native 精解与实战》书籍连载「Node.js 简介与 React Native 开发环境配置」

    此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...

  2. 小L的项链切割 (回文串)

    题目描述 小T送给了小L了一串项链.为了方便,我们把项链上形态不同钻石用不同的字母表示.这样小L的项链就变成了一个字符串.小L忽然想把这串项链优美地切割一下,她想把它切割成尽量少的回文项链,啊也就是回 ...

  3. python札记

    进制转换 num = "0011"v = int(num, base=16)print(v)2->16

  4. Java对象的创建、内存布局和访问定位

    在Java运行时数据区中,我们知道了虚拟机内存的概况,本文介绍虚拟机内存中的数据的其它细节,如对象如何创建.如何布局以及如何访问. 基于实用的原则,这里以HotSpot虚拟机和常用的内存区域Java堆 ...

  5. 爬虫——cookies池的搭建

    https://github.com/Python3WebSpider/cookiesPool

  6. ORACLE 当字段中有数据如何修改字段类型

    创建视图的时候,因为表太多,里面一些字段类型不一样,PL/SQL报错,为‘表达式必须具有对应表达式相同的数据类型’,发现后,一个字段的类型为CLOB和VARCHAR2(4000)两种,将CLOB进行修 ...

  7. react 组件列表

    let data=[ [ '同时入选IMDB250和豆瓣电影250的电影', '带你进入不正常的世界', '用电[影]来祭奠逝去的岁月', '女孩们的故事[电影]', '', '使用 App [找电影 ...

  8. node-cookie-parserDemo

    let express = require('express'); let app = new express(); let cookieParser = require('cookie-parser ...

  9. C# 父子页面传值

    业务需求是:父页面点击“选择任务”按钮进入任务列表页.(项目进度周报) 父页面如下: 任务列表页: 选择某一个任务,点击“确定”后返回父页面所需数据. 父页面“选择任务” 按钮触发事件. /// &l ...

  10. Laravel5 创建自定义门面(Facade)

    门面为应用服务容器中的绑定类提供了一个“静态”接口.Laravel 内置了很多门面,你可能在不知道的情况下正在使用它们.Laravel 的门面作为服务容器中底层类的“静态代理”,相比于传统静态方法,在 ...