Read problems statements in Mandarin Chineseand Russian.

Rin is attending a university.

She has M semesters to finish her program, and that program has N required courses. Each course must be taken in exactly one of the semesters.

Some courses have prerequisites: for each i from 1 to K, she must take course A[i]before course B[i].

The same course may be taught by different professors in different semesters, and how well she does will depend on which professor teaches her. Additionally, some courses may not be taught every semester.

We are given an array X representing this information. For each course i and each semester jX[i][j] = -1 if course i is not taught in semester j. Otherwise, X[i][j] will be an integer between 0 and 100: the expected score Rin will get if she takes course i in semester j.

Rin may take any number of courses per semester, including none, as long as they are taught that semester and she has already taken any required prerequisite courses.

Help Rin to find the maximal average score she can get over her whole program.

Input

The first line contain 3 integers: NM and K.

This is followed by N lines, each containing M integers. The jth integer on the ithline represents the value of X[i][j].

This is followed by K lines, each containing two integers: A[i] and B[i].

Output

Output one real number: the maximal average score, rounded to 2 digits after the decimal point.

Constraints

  • 1 ≤ MN ≤ 100
  • 0 ≤ K ≤ 100
  • -1 ≤ X[i][j] ≤ 100
  • 1 ≤ A[i]B[i] ≤ N
  • For each iA[i] ≠ B[i].
  • For different i and j, (A[i]B[i]) ≠ (A[j]B[j]).
  • We guarantee there exists a way to take these N courses in M semesters.

Subtasks

Subtask 1: (20 Points) A course can have at most 1 pre request course.

Subtask 2: (80 Points) Refer to constraints above

Example

Input 1:
3 2 2
70 100
100 80
100 90
1 2
1 3 Output 1:
80.00 Input 2:
4 5 4
20 -1 100 -1 -1
100 30 -1 -1 -1
100 -1 30 20 40
100 30 40 50 20
1 2
1 3
2 4
3 4 Output 2:
32.50

Explanation

Example case 1

The only way she can finish these 3 courses is: take course 1 in the first semester, then take courses 2 and 3 in the second semester. The average score is (70 + 80 + 90) / 3 = 80.00.

Example case 2

The optimal solution is: take course 1 in semester 1, course 2 in semester 2, course 3 in semester 3 and course 4 in semester 4.

类似于HNOI切糕 的建模,首先可以证明最小割一定会割正好N条边,并且每条边都在每个课程的一条链上,所以我们把边权w变成200-w,最后答案就是 200*N-max_flow()。

而强制要求课程的先后顺序,就可以通过链之间连 inf 来实现。

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
const int maxn=20005;
const int inf=1<<30;
using namespace std;
vector<int> g[maxn];
struct lines{
int to,flow,cap;
}l[maxn*437];
int t=-1,S,T,d[maxn],cur[maxn];
bool v[maxn]; inline void add(int from,int to,int cap){
l[++t]=(lines){to,0,cap},g[from].pb(t);
l[++t]=(lines){from,0,0},g[to].pb(t);
} inline bool BFS(){
queue<int> q;
memset(v,0,sizeof(v));
q.push(S),v[S]=1,d[S]=0;
int x; lines e; while(!q.empty()){
x=q.front(),q.pop();
for(int i=g[x].size()-1;i>=0;i--){
e=l[g[x][i]];
if(e.flow<e.cap&&!v[e.to]){
v[e.to]=1,d[e.to]=d[x]+1;
q.push(e.to);
}
}
}
return v[T];
} int dfs(int x,int A){
if(x==T||!A) return A;
int flow=0,f,sz=g[x].size();
for(int &i=cur[x];i<sz;i++){
lines &e=l[g[x][i]];
if(d[x]==d[e.to]-1&&(f=dfs(e.to,min(e.cap-e.flow,A)))){
A-=f,flow+=f;
e.flow+=f,l[g[x][i]^1].flow-=f;
if(!A) break;
}
}
return flow;
} inline int max_flow(){
int an=0;
while(BFS()){
memset(cur,0,sizeof(cur));
an+=dfs(S,1<<30);
}
return an;
} int N,M,K,uu,vv;
int main(){
scanf("%d%d%d",&N,&M,&K),S=0,T=N*(M+1)+1;
for(int i=1;i<=N;i++) add(S,i,inf),add(i+M*N,T,inf);
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++){
scanf("%d",&uu);
if(uu<0) add(i+(j-1)*N,i+j*N,inf);
else add(i+(j-1)*N,i+j*N,200-uu);
}
while(K--){
scanf("%d%d",&uu,&vv);
for(int j=0;j<M;j++) add(uu+j*N,vv+(j+1)*N,inf);
} printf("%.2lf\n",200-max_flow()/(double)N);
return 0;
}

  

CodeChef - RIN Course Selection的更多相关文章

  1. Course Selection CodeChef - RIN

    All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russ ...

  2. Codechef RIN 「Codechef14DEC」Course Selection 最小割离散变量模型

    问题描述 提供中文版本好评,一直以为 Rin 是题目名字... pdf submit 题解 参考了 东营市胜利第一中学姜志豪 的<网络流的一些建模方法>(2016年信息学奥林匹克中国国家队 ...

  3. [CODECHEF]RIN

    题意:一个人要在$m$个学期上$n$节课,在第$j$学期上$i$课有$X_{i,j}$的收益,有些课$B_i$有前置课程$A_i$,问最大得分 这个题我都做不出来还去看题解...我退役吧== 考虑每种 ...

  4. CodeChef - RIN 最小割应用 规划问题

    题意:给定\(n\)门课和\(m\)个学期,每门课在每个学期有不同的得分,需要选定一个学期去完成,但存在约束条件,共有\(k\)对课程需要\(a\)在\(b\)开始学前学会,求最大得分(原问题是求最高 ...

  5. [CodeChef]RIN(最小割)

    Description  有m门课可以在n个学期内学习,第i门课在第j个学期的收益是\(X_{i,j}\),一个学期可以学多门课,有的课之间有依赖关系,即必须先学a再学b,求最大收益.n,m<= ...

  6. Codechef Course Selection

    Home » Practice(Hard) » Course Selection Course Selection Problem Code: RINSubmit https://www.codech ...

  7. codechef营养题 第三弹

    第三弾が始まる! codechef problems 第三弹 一.Motorbike Racing 题面 It's time for the annual exciting Motorbike Rac ...

  8. codechef营养题 第二弹

    第二弾が始まる! codechef problems 第二弹 一.Backup Functions 题面 One unavoidable problem with running a restaura ...

  9. codechef 营养题 第一弹

    第一弾が始まる! 定期更新しない! 来源:http://wenku.baidu.com/link?url=XOJLwfgMsZp_9nhAK15591XFRgZl7f7_x7wtZ5_3T2peHh5 ...

随机推荐

  1. yield关键字有什么作用

    所属网站分类: python基础 > 语句 作者:goodbody 链接: http://www.pythonheidong.com/blog/article/10/ 来源:python黑洞网  ...

  2. Altium Designer入门学习笔记1.软件安装与资料收集

    一.软件安装 微信:http://url.cn/5Eudzt9 关注微信公众号"软件安装管家",点击"软件目录",弹出"软件目录",点击进入 ...

  3. poj--1064

    题意:有N条绳子,它们的长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子最长能有多长?答案保留到小数点后2位. 思路:这些最大最小化问题大多数可以用二分查找的方法来解题 用 d 表 ...

  4. Linux磁盘简介

    为一台服务器添加三块磁盘的体系结构情况 Linux系统中用free  -l 查看磁盘的状况 说明:   1)buffers为写入缓冲区,sync将缓冲区数据写入磁盘,cache为读出缓存. 2)cac ...

  5. holtek编程注意事项

    1.holtek单片机中断服务函数中函数调用里的参数不能传递地址,不然程序就会跑飞 2.holtek单片机尽量不要函数嵌套很多层,嵌套过多,会导致单片机复位

  6. CSS(非布局样式)

    CSS(非布局样式) 问题1.CSS样式(选择器)的优先级 1.计算权重 2.!important 3.内联样式比外嵌样式高 4.后写的优先级高 问题2.雪碧图的作用 1.减少 HTTP 请求数,提高 ...

  7. 《Scrum实战》第1次课课后任务

    1.必做任务:从知行角度总结T平台 从知行角度总结T平台 头(知识,学习) 做得好的 宣贯会 引入敏捷思想 敏捷宣言 敏捷原则 质量风险前移原则 引入最佳实践 包括了XP的大部分实践 不足 项目管理框 ...

  8. day05 模块以及内置常用模块用法

    内置常用模块详解: 1 time 2 datetime 3 random   4 os 5 sys 6 shutil 7 shelve 8 xml 9 configparser 10 hashlib ...

  9. PDO PDO_MYSQL MYSQLI MYSQL 的区别

    MYSQL,MYSQLI 这两个扩展本身就是访问MYSQL数据库的驱动 PDO则是一个抽象层接口 向程序员提供可调用的API是由,MYSQL驱动.MYSQLI驱动,以及PDO来提供. PDO_MYSQ ...

  10. 九度oj 题目1356:孩子们的游戏(圆圈中最后剩下的数)

    题目描述: 每年六一儿童节,JOBDU都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.HF作为JOBDU的资深元老,自然也准备了一些小游戏.其中,有个游戏是这样的:首先,让小朋友们围成一个大圈. ...