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的更多相关文章

  1. 正则表达式和文本挖掘(Text Mining)

    在进行文本挖掘时,TSQL中的通配符(Wildchar)显得功能不足,这时,使用“CLR+正则表达式”是非常不错的选择,正则表达式看似非常复杂,但,万变不离其宗,熟练掌握正则表达式的元数据,就能熟练和 ...

  2. 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 ...

  3. Distributed Databases and Data Mining: Class timetable

    Course textbooks Text 1: M. T. Oszu and P. Valduriez, Principles of Distributed Database Systems, 2n ...

  4. coursera 公开课 文本挖掘和分析(text mining and analytics) week 1 笔记

    一.课程简介: text mining and analytics 是一门在coursera上的公开课,由美国伊利诺伊大学香槟分校(UIUC)计算机系教授 chengxiang zhai 讲授,公开课 ...

  5. 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 ...

  6. POJ 2948 Martian Mining

    Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...

  7. 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 ...

  8. A web crawler design for data mining

    Abstract The content of the web has increasingly become a focus for academic research. Computer prog ...

  9. Datasets for Data Mining and Data Science

    https://github.com/mattbane/RecommenderSystem http://grouplens.org/datasets/movielens/ KDDCUP-2012官网 ...

随机推荐

  1. Linux下rpm仓库搭建

    一.概念 1.rpm是什么?在帮助文档里我们可以看到,rpm的名字是rpm package manage 的缩写, 从名字上看就可以知道rpm就是一个包管理工具.简单说rpm包就是把一些程序编译成二进 ...

  2. 015.Kubernetes二进制部署所有节点kubelet

    一 部署 kubelet kubelet 运行在每个 worker 节点上,接收 kube-apiserver 发送的请求,管理 Pod 容器,执行交互式命令,如 exec.run.logs 等. k ...

  3. Maven系列第6篇:生命周期和插件详解,此篇看过之后在maven的理解上可以超越同级别90%的人!

    maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第6篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...

  4. SQLite性能 - 它不是内存数据库,不要对IN-MEMORY望文生意。

    SQLite创建的数据库有一种模式IN-MEMORY,但是它并不表示SQLite就成了一个内存数据库.IN-MEMORY模式可以简单地理解为,本来创建的数据库文件是基于磁盘的,现在整个文件使用内存空间 ...

  5. [FPGA]Verilog实现可自定义的倒计时器(24秒为例)

    目录 想说的话... 样例_边沿检测计数器 代码讲解 仿真演示 拓展_自定义倒计时数和倒计时间隔 代码讲解 仿真演示 总结 实例_24秒倒计时器 想说的话... 本次实现的是一个24秒倒计时器,功能顾 ...

  6. ASP.NET Core gRPC 使用 Consul 服务注册发现

    一. 前言 gRPC 在当前最常见的应用就是在微服务场景中,所以不可避免的会有服务注册与发现问题,我们使用gRPC实现的服务可以使用 Consul 或者 etcd 作为服务注册与发现中心,本文主要介绍 ...

  7. Android的系统框架的深入认识

    Android采用层次化系统架构,官方公布的标准架构如下图所示.Android由底层往上分为4个主要功能层,分别是linux内核层(Linux Kernel),系统运行时库层(Libraries和An ...

  8. Python3 之 类属性与实例属性

    1.类属性与实例属性 类属性就相当与全局变量,实例对象共有的属性,实例对象的属性为实例对象自己私有. 类属性就是类对象(Tool)所拥有的属性,它被所有类对象的实例对象(实例方法)所共有,在内存中只存 ...

  9. Tomcat安装和使用

    1.Tomcat简介 Tomcat是Apache开源组织下的开源免费的中小型Web应用服务器,支持javaEE中的servlet和jsp规范. 2.Windows版安装和使用 下载地址:http:// ...

  10. Netty Pipeline与ChannelHandler那些事

    Pipeline和ChannelHandler是Netty处理流程的重要组成部分,ChannelHandler对应一个个业务处理器,Pipeline则是负责将各个ChannelHandler串起来的& ...