B1391 [Ceoi2008]order 最大权闭合图 最小割

啊啊啊,假的题吧!!!我用的当前弧优化T了6个点,其他人不用优化AC!!!震惊!!!当前弧优化是假的吧!!!

到现在我也没调出来。。。大家帮我看看为啥70.。。。

来讲一下这个题的思路,就是设一个源点,向每一个任务建边,边权为任务价值。然后任务向机器建边,边权为租金,最后机器向汇点建边,边权为购买的费用。

但这个题题意不明确,好像租完一个机器,还要花费购买的钱。

题干:

Description
有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成。 现在给出这些参数,求最大利润
Input
第一行给出 N,M(1<=N<=1200,1<=M<=1200) 下面将有N块数据,每块数据第一行给出完成这个任务能赚到的钱(其在[1,5000])及有多少道工序 接下来若干行每行两个数,分别描述完成工序所需要的机器编号及租用它的费用(其在[1,20000]) 最后M行,每行给出购买机器的费用(其在[1,20000])
Output
最大利润
Sample Input
2 3

100 2

1 30

2 20

100 2

1 40

3 80

50

80

110
Sample Output
50
HINT

Source

70分代码(欢迎大佬们指出我的错误啊)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = 1 << 30;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
    char c;
    bool op = 0;
    while(c = getchar(), c < '0' || c > '9')
        if(c == '-') op = 1;
    x = c - '0';
    while(c = getchar(), c >= '0' && c <= '9')
        x = x * 10 + c - '0';
    if(op) x = -x;
}
template <class T>
void write(T x)
{
    if(x < 0) putchar('-'), x = -x;
    if(x >= 10) write(x / 10);
    putchar('0' + x % 10);
}
struct node{
    int x,y,w,next,other;
}a[2200000];
int len = 0,last[1200000],n,m,st = 0,ed;
void add(int x,int y,int w)
{
    int k1,k2;
    a[++len].next = last[x];    k1 = len;
    a[len].x = x;    a[len].y = y;
    a[len].w = w;    last[x] = len;
    a[++len].next = last[y];    k2 = len;
    a[len].x = y;    a[len].y = x;
    a[len].w = 0;    last[y] = len;
    a[k1].other = k2;    a[k2].other = k1;
}
int qu[1000005],h[1000005],ans = 0;
int cur[1000005];
bool bfs()
{
    clean(h);
    int head = 1,tail = 2;
    qu[head] = st;
    h[st] = 1;
    while(head != tail)
    {
        int x = qu[head];
//        cout<<x<<endl;
        for(int k = last[x];k;k = a[k].next)
        {
            int y = a[k].y;
            if(h[y] == 0 && a[k].w > 0)
            {
                h[y] = h[x] + 1;
                qu[tail++] = y;
            }
        }
        head++;
    }
    if(h[ed] > 0)
    return true;
    else
    return false;
}
int dfs(int x,int f)
{
    if(x == ed)
    return f;
    int s = 0,t;
    for(int k = cur[x];k;k = a[k].next,cur[x] = k)
    {
        int y = a[k].y;
        if(s < f && h[y] == (h[x] + 1) && a[k].w > 0)
        {
            t = dfs(y,min(a[k].w,f - s));
            s += t;
            a[k].w -= t;
            a[a[k].other].w += t;
        }
    }
    if(s == 0)
    h[x] = 0;
    return s;
}
int main()
{
    read(n);read(m);
    ed = n + m + 1;
    int p,q,e,r;
    duke(i,1,n)
    {
        read(p);
        ans += p;
        add(st,i,p);
        read(q);
        duke(j,1,q)
        {
            read(e);read(r);
            add(i,e + n,r);
        }
    }
    duke(i,1,m)
    {
        read(r);
        add(n + i,ed,r);
    }
    while(bfs())
    {
        duke(i,0,n + m + 1)
        cur[i] = last[i];
        ans -= dfs(0,INF);
//        cout<<ans<<endl;
    }
    write(ans);
    return 0;
}
/*
2 3
100 2
1 30
2 20
100 2
1 40
3 80
50
80
110
*/
原文地址:https://www.cnblogs.com/DukeLv/p/9503651.html