题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3667

思路:由于花费的计算方法是a*x*x,因此必须拆边,使得最小费用流模板可用,即变成a*x的形式。具体的拆边方法为:第i次取这条路时费用为(2*i-1)*a (i<=5),每条边的容量为1。如果这条边通过的流量为x,那正好sigma(2*i-1)(1<<i<<x)==x^2。然后就是跑最小费用最大流了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 222
#define MAXM 22222222
#define inf 1<<30 struct Edge{
int v,cap,cost,next;
}edge[MAXM]; int n,m,k,NE;
int head[MAXN]; void Insert(int u,int v,int cap,int cost)
{
edge[NE].v=v;
edge[NE].cap=cap;
edge[NE].cost=cost;
edge[NE].next=head[u];
head[u]=NE++; edge[NE].v=u;
edge[NE].cap=;
edge[NE].cost=-cost;
edge[NE].next=head[v];
head[v]=NE++;
} int dist[MAXN];
bool mark[MAXN];
int cur[MAXN],pre[MAXN];
bool spfa(int vs,int vt)
{
memset(mark,false,sizeof(mark));
fill(dist,dist+n+,inf);
dist[vs]=;
queue<int>que;
que.push(vs);
while(!que.empty()){
int u=que.front();
que.pop();
mark[u]=false;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].v,cost=edge[i].cost;
if(edge[i].cap>&&dist[u]+cost<dist[v]){
dist[v]=dist[u]+cost;
pre[v]=u;
cur[v]=i;
if(!mark[v]){
mark[v]=true;
que.push(v);
}
}
}
}
return dist[vt]<inf;
} int MinCostFlow(int vs,int vt)
{
int cost=,flow=;
while(spfa(vs,vt)){
int aug=inf;
for(int u=vt;u!=vs;u=pre[u]){
aug=min(aug,edge[cur[u]].cap);
}
flow+=aug;cost+=dist[vt]*aug;
for(int u=vt;u!=vs;u=pre[u]){
edge[cur[u]].cap-=aug;
edge[cur[u]^].cap+=aug;
}
}
if(flow<k)cost=-;
return cost;
} int main()
{
int u,v,cost,cap;
while(~scanf("%d%d%d",&n,&m,&k)){
NE=;
memset(head,-,sizeof(head));
while(m--){
scanf("%d%d%d%d",&u,&v,&cost,&cap);
for(int i=;i<=cap;i++){
Insert(u,v,,(*i-)*cost);
}
}
Insert(,,k,);
printf("%d\n",MinCostFlow(,n));
}
return ;
}

hdu 3667(拆边+最小费用最大流)的更多相关文章

  1. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  2. hdu 4494 Teamwork 最小费用最大流

    Teamwork Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4494 ...

  3. HDU 4862 JUMP 最小费用最大流

    2014 多校的B题,由于我不怎么搞图论,当时碰到这个题目,我怎么想都没往网络流方面弄,不过网络流真的是个好东西,对于状态多变,无法用动规或者数据结构来很好表示的时候,非常有用 这个题目要求每个点一定 ...

  4. POJ 2195 Going Home / HDU 1533(最小费用最大流模板)

    题目大意: 有一个最大是100 * 100 的网格图,上面有 s 个 房子和人,人每移动一个格子花费1的代价,求最小代价让所有的人都进入一个房子.每个房子只能进入一个人. 算法讨论: 注意是KM 和 ...

  5. hdu3667 Transportation 费用与流量平方成正比的最小流 拆边法+最小费用最大流

    /** 题目:hdu3667 Transportation 拆边法+最小费用最大流 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3667 题意:n个城市由 ...

  6. hdu 1533 Going Home 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 On a grid map there are n little men and n house ...

  7. HDU 5988.Coding Contest 最小费用最大流

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  8. hdu 2686&&hdu 3376(拆点+构图+最小费用最大流)

    Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  9. hdu 3488(KM算法||最小费用最大流)

    Tour Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

随机推荐

  1. 【BIRT】报表数据导出为PDF显示不全

    正常导出方法 导出结果 从上图可以看出,缺失了一部分 解决问题 那么我们采用以下方法导出即可: 导出结果: 完美解决问题.

  2. 解析theme()

    drupal_render()只是对theme()的调用做了包装,真正做任务的还是theme(). function theme($hook, $variables = array()) { ... ...

  3. Android开发之帐户管理

    android.accounts主要包括了集中式的帐户管理API, AccountManagerCallback, AccountManagerFuture, OnAccountsUpdateList ...

  4. 【TP3.2】模板布局和文件引入

    TP3.2框架引入文件使用<include file="blue/common/header">标签,==>blue主题下的公共头文件(blue放在View/目录 ...

  5. 【C++】排序算法小结

    1.计数排序 如果给定上下界,并且区间不大的话,最适用. 比如对于英文字母数组进行排序. 时间复杂度O(n),空间复杂度O(n) void countSort(int A[], int n, int ...

  6. Bootstrap 的模态框类

    事件类型 描述 show.bs.modal show 方法调用之后立即触发该事件.如果是通过点击某个作为触发器的元素,则此元素可以通过事件的relatedTarget 属性进行访问. shown.bs ...

  7. Linux 设置IP,gate, 以及自动获取IP的方法

    一.使用命令设置ubuntu的ip地址 1.修改配置文件blacklist.conf禁用IPV6: sudo vi /etc/modprobe.d/blacklist.conf 2.在文档最后添加 b ...

  8. Oracle开发者守则

    下面为Oracle大师级语录: Oracle Database developers should follow is to do everything they can in SQL. What t ...

  9. Lintcode---翻转二叉树

    翻转一棵二叉树 您在真实的面试中是否遇到过这个题? Yes 样例 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 思路:依旧采用递归的思路,判断特殊条件后,先交换根节点的左右孩子, ...

  10. WIN10 无法访问2003 server共享

    With Windows 10 v1803 or Spring Creators update released I have decided to do a fresh installation o ...