【刷题】HDU 4966 GGS-DDU

news/2025/3/20 22:45:55/

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级。现在要选择一些课程进行学习使得每一个科目都达到最高等级。有m节课。对于每门课给出c1[i],L1[i],c2[i],L2[i],money[i],要选择这门课要求科目c1[i]的等级不小于L1[i],可以使科目c2[i]的等级升为L2[i],花费金钱money[i]。请计算最小花费是多少。

Solution

最小树形图
每门科目每个等级都设为一个点
所有课都对应一条权值为花费金钱的有向边
然后对于每一门课,将它的每个等级都向低一级连一条 \(0\) 费的边,那么只要到达高等级,低等级一定选到,并且不会影响最终代价
于是建个超级源点跑最小树形图就好了

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=600+10,MAXM=MAXN*MAXN,inf=0x3f3f3f3f;
int n,m,sum[MAXN],vis[MAXN],pre[MAXN],in[MAXN],bel[MAXN],snt,s,a[MAXN];
struct node{int u,v,k;
};
node side[MAXM];
template<typename T> inline void read(T &x)
{T data=0,w=1;char ch=0;while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();if(ch=='-')w=-1,ch=getchar();while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline int id(int les,int lvl)
{return sum[les-1]+lvl+1;
}
inline int solve(int rt,int n)
{int res=0;while(true){for(register int i=1;i<=n;++i)in[i]=inf;for(register int i=1;i<=snt;++i)if(side[i].u!=side[i].v&&in[side[i].v]>side[i].k)in[side[i].v]=side[i].k,pre[side[i].v]=side[i].u;for(register int i=1;i<=n;++i)if(i!=rt&&in[i]==inf)return -1;int cnt=0;memset(vis,0,sizeof(vis));memset(bel,0,sizeof(bel));in[rt]=0;for(register int i=1,j;i<=n;++i){res+=in[i];j=i;while(j!=rt&&vis[j]!=i&&!bel[j])vis[j]=i,j=pre[j];if(j!=rt&&!bel[j]){bel[j]=++cnt;for(register int k=pre[j];k!=j;k=pre[k])bel[k]=cnt;}}if(!cnt)break;for(register int i=1;i<=n;++i)if(!bel[i])bel[i]=++cnt;for(register int i=1,u,v;i<=snt;++i){u=side[i].u,v=side[i].v;side[i].u=bel[u],side[i].v=bel[v];if(bel[u]^bel[v])side[i].k-=in[v];}n=cnt;rt=bel[rt];}return res;
}
int main()
{while(scanf("%d%d",&n,&m)!=EOF){if(!n&&!m)break;snt=0;for(register int i=1;i<=n;++i)read(a[i]),sum[i]=sum[i-1]+a[i]+1;for(register int i=1;i<=m;++i){int c1,l1,c2,l2,money;read(c1);read(l1);read(c2);read(l2);read(money);side[++snt]=(node){id(c1,l1),id(c2,l2),money};}for(register int i=1;i<=n;++i)for(register int j=a[i];j>=1;--j)side[++snt]=(node){id(i,j),id(i,j-1),0};s=sum[n]+1;for(register int i=1;i<=n;++i)side[++snt]=(node){s,id(i,0),0};write(solve(s,s),'\n');}return 0;
}

转载于:https://www.cnblogs.com/hongyj/p/9285748.html


http://www.ppmy.cn/news/928274.html

相关文章

hdu 4966 GGS-DDU 最小树形图

来自九野~ 给定n个技能&#xff0c;m个限制 下面是每个技能满级的级数 开始每个技能都是0级。 m个限制 (c,l1) (d,l2) cost 若c技能已经>l1级&#xff0c;那么把点亮d技能 从0级一路点到l2级的花费是cost 。。他说的好有道理&#xff0c;我竟无言以对 _(:зゝ∠)_ 最小树形图…

HDU 4966 GGS-DDU

题意&#xff1a; 你有n个课程 每个课程有一个规定的毕业学分 修学分有m种方式 每种方式要求先修到x课程x学分以上才能花费money去修y课程并且将学分修到y 问 最少花费多少可以毕业 思路&#xff1a; 一开始想费用流 建完图发现一个问题解决不掉 那就是 一条边如果流…

将安装包 ggs_Adapters_Linux_x64.tar 在主机的 GG_HOME 下解压,环境变量GG_HOME没有目录

背景&#xff1a;我在做项目练习的时候&#xff0c;目标端 GoldenGate 安装时需要在主机的 GG_HOME 下解压安装包 第一反应是环境变量没有生效 在root下source $GG_HOME 使其生效&#xff0c;然后重启重新登陆 一般就能解决 在我这里他没有解决 echo $GG_HOME是好的 那就…

ORA-1653: unable to extend table GGS.GGS_DDL_HIST

1.表GGS_DDL_HIST由来 这张表是在GLOBALS里面参数DDLTABLE指定的&#xff0c;若是没有指定默认就是这个表名GGS_DDL_HIST 此表记录了被goldengate处理过的DDL&#xff0c;也就是通过goldengate同步到对端的DDL GGSCI (TEST)> EDIT PARAMS ./GLOBALS DDLTABLE GGS_DDL_HIS…

win7系统oracle搭建ogg,OGG_windows搭建实验

windows卸载Oracle GoldenGate产品的方法 1、进入源或目标GG配置目录&#xff0c;输入以下命令&#xff1a; gg> stop * gg> stop mgr 2、删除Oracle GoldenGate目录 3、运行windows命令&#xff0c;执行sc delete [服务名] 此服务器名就是./GLOBALS中的MGRSERVNAME ggsc…

【HDU4966】GGS-DDU

题意 有n种科目&#xff0c;每个科目都有一个最高的等级a[i]。开始的时候&#xff0c;每个科目的等级都是0。现在要选择一些课程进行学习使得每一个科目都达到最高等级。这里有m节课可供选择。对于每门课给出L1[i],c[i],L2[i],d[i]&#xff0c;money[i]&#xff0c;要选择这门课…

HDU 4966 GGS-DDU [最小树形图]

题意 一共有n门课&#xff0c;每门课有a[i]个阶段&#xff0c;一开始每门课都在第0个阶段&#xff0c;我们需要到达所有课的最高的阶段&#xff0c;现在有m个培训班&#xff0c;每个培训班需要c[i]课程满足所在阶段大于等于l1&#xff0c;那么就可以到达d课程l2的阶段&#xf…

ORA-04098: trigger ‘SYS.GGS_DDL_TRIGGER_BEFORE‘ is invalid and failed re-validation处理

作者&#xff1a;IT邦德 中国DBA联盟(ACDU)成员&#xff0c;目前从事DBA及程序编程 &#xff08;Web\java\Python&#xff09;工作&#xff0c;主要服务于生产制造 现拥有 Oracle 11g OCP/OCM、 Mysql、Oceanbase&#xff08;OBCA&#xff09;认证 分布式TBase\TDSQL数据库、国…