Open-Pit Mining
Description
Open-pit mining is a surface mining technique of extracting rock or minerals from the earth by their removal from an open pit or borrow. Open-pit mines are used when deposits of commercially useful minerals or rocks are found near the surface. Automatic Computer Mining (ACM) is a company that would like to maximize its profits by open-pit mining. ACM has hired you to write a program that will determine the maximum profit it can achieve given the description of a piece of land.
Each piece of land is modelled as a set of blocks of material. Block i has an associated value (vi), as well as a cost (ci), to dig that block from the land. Some blocks obstruct or bury other blocks. So for example if block i is obstructed by blocks j and k, then one must first dig up blocks j and k before block i can be dug up. A block can be dug up when it has no other blocks obstructing it.
Input
The first line of input is an integer N(1≤N≤200)N(1≤N≤200) which is the number of blocks. These blocks are numbered 1 through N. Then follow N lines describing these blocks. The ith such line describes block i and starts with two integers vi, ci denoting the value and cost of the ith block (0≤vi,ci≤200)(0≤vi,ci≤200) . Then a third integer 0≤mi≤N−10≤mi≤N−1 on this line describes the number of blocks that block i obstructs. Following that are mi distinct space separated integers between 1 and N (but excluding i) denoting the label(s) of the blocks that block i obstructs. You may assume that it is possible to dig up every block for some digging order. The sum of values mi over all blocks i will be at most 500.
Output
Output a single integer giving the maximum profit that ACM can achieve from the given piece of land.
Sample Input
5
0 3 2 2 3
1 3 2 4 5
4 8 1 4
5 3 0
9 2 0
Sample Output
2
Hint
数论:网络流:最大权闭合子图,模板题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e6+5;
const int INF=0x3f3f3f3f;
struct node{
ll t,cap,flow,next;
}e[N];
int head[N],cur[N],cnt;
void init(){
memset(head,-1,sizeof(head));
cnt=0;
}
void add(int u,int v,ll cap)
{
e[cnt]=node{v,cap,0,head[u]};
head[u]=cnt++;
e[cnt]=node{u,0,0,head[v]};
head[v]=cnt++;
}
int d[N];
bool bfs(int s,int t) //O(n+m)
{
memset(d,0,sizeof(d));
queue<int>q;
q.push(s);
d[s]=1;
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=head[u];~i;i=e[i].next)
{
int v=e[i].t;
if(d[v]==0&&e[i].cap-e[i].flow>0)
{
d[v]=d[u]+1;
q.push(v);
}
}
}
return d[t]>0;
}
ll dfs(int s,int t,ll minedge)
{
if(s==t)return minedge;
ll flow=0;
for(int &i=cur[s];~i;i=e[i].next)
{
int v=e[i].t;
if(d[v]==d[s]+1&&e[i].cap-e[i].flow>0)
{
ll temp=dfs(v,t,min(minedge-flow,e[i].cap-e[i].flow));
e[i].flow+=temp;
e[i^1].flow-=temp;
flow+=temp;
if(flow==minedge)return flow;
}
}
if(flow==0)d[s]=0;
return flow;
}
ll dinic(int s,int t)
{
ll maxflow=0;
while(bfs(s,t))
{
memcpy(cur,head,sizeof(head));
maxflow+=dfs(s,t,INF);
}
return maxflow;
}
int pro[220];
int main()
{
int n,u,v,x,k;
init();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&u,&v,&k);
pro[i]=u-v;
while(k--){
scanf("%d",&x);
add(x,i,INF);
}
}
ll sum=0;
for(int i=1;i<=n;i++)
{
if(pro[i]>0){
add(0,i,pro[i]);
sum+=pro[i];
}
else if(pro[i]<0)add(i,n+1,-pro[i]);
}
int ans=dinic(0,n+1);
cout<<sum-ans<<endl;
return 0;
}
Open-Pit Mining的更多相关文章
- 正则表达式和文本挖掘(Text Mining)
在进行文本挖掘时,TSQL中的通配符(Wildchar)显得功能不足,这时,使用“CLR+正则表达式”是非常不错的选择,正则表达式看似非常复杂,但,万变不离其宗,熟练掌握正则表达式的元数据,就能熟练和 ...
- Call for Papers IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM)
IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...
- Distributed Databases and Data Mining: Class timetable
Course textbooks Text 1: M. T. Oszu and P. Valduriez, Principles of Distributed Database Systems, 2n ...
- coursera 公开课 文本挖掘和分析(text mining and analytics) week 1 笔记
一.课程简介: text mining and analytics 是一门在coursera上的公开课,由美国伊利诺伊大学香槟分校(UIUC)计算机系教授 chengxiang zhai 讲授,公开课 ...
- What is the most common software of data mining? (整理中)
What is the most common software of data mining? 1 Orange? 2 Weka? 3 Apache mahout? 4 Rapidminer? 5 ...
- POJ 2948 Martian Mining
Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...
- What’s the difference between data mining and data warehousing?
Data mining is the process of finding patterns in a given data set. These patterns can often provide ...
- A web crawler design for data mining
Abstract The content of the web has increasingly become a focus for academic research. Computer prog ...
- Datasets for Data Mining and Data Science
https://github.com/mattbane/RecommenderSystem http://grouplens.org/datasets/movielens/ KDDCUP-2012官网 ...
随机推荐
- 可保图片不变形的object-fit
Object-fit 我们有时候浏览一些网站的时候,偶尔会遇到这种情况: 明显它喵的形变了,尤其是这种这么业余的失误,还是出现在一个专门做图片的网站上. 产生这种现象的原因是:图片写了固定的宽高,这 ...
- avtivmq(订阅写法)
发布-订阅消息模式与点对点模式类似,只不过在session创建消息队列时,由session.createQuene()变为session.createTopic(). 消息发布者代码: 消息订阅者代码 ...
- php的精度计算问题(bcadd和bcsub)
一.前言 我们在进行php开发的时候经常会遇到浮点型的问题,特别是涉及金额的部分,常常需要进行加减运算.当小数点的位数比较多的时候,往往容易犯一些很低级的错误.这里记录一下php的精度计算和封装的小d ...
- java编程思想第四版第十八章总结
一.概述 如何学习java I/O 学习I/O类库 学习I/O发展史,为什么要学习发展史呢? 因为,如果缺乏发展史,我们就会对什么时候使用哪个类,以及什么时候不该使用它们而感到迷惑. 了解nio 二. ...
- ESP8266 使用AT指令
ESP8266 使用AT指令 问题:串口调试工具输入AT指令没返回结果 分析板子有两种模式 下载模式(默认) 运行模式 解决办法: 方法一:按下板子上的 RST 键位 方法二:使用 [安信可串口调试工 ...
- nyoj 170-网络的可靠性 (度为1)
170-网络的可靠性 内存限制:64MB 时间限制:3000ms 特判: No 通过数:15 提交数:21 难度:3 题目描述: A公司是全球依靠的互联网解决方案提供商,也是2010年世博会的高级赞助 ...
- 命令序列 ; & && ||
; 从左到右依次被执行,返回最后一个命令的执行状态 & 该命令将在后台被执行,即在子bash中执行(或ctrl+z,bg, jobs,bg 命令号)(变量$!.$one.$two.$three ...
- 使用shiro做权限管理的学习笔记整理
Shiro权限管理 参考:https://www.cnblogs.com/jpfss/p/8352031.html Shiro解决的问题 授权和鉴别的问题:Authenrization(授权) Aut ...
- Swoft 源码剖析 - Swoole和Swoft的那些事 (Http/Rpc服务篇)
前言 Swoft在PHPer圈中是一个门槛较高的Web框架,不仅仅由于框架本身带来了很多新概念和前沿的设计,还在于Swoft是一个基于Swoole的框架.Swoole在PHPer圈内学习成本最高的工具 ...
- <<代码大全>>阅读笔记之一 使用变量的一般事项
一.使用变量的一般事项 1.把变量引用局部化 变量应用局部化就是把变量的引用点尽可能集中在一起,这样做的目的是增加代码的可读性 衡量不同引用点靠近程度的一种方法是计算该变量的跨度(span) 示例 a ...