"Can't continue the wave" BZ to do the title record [7.01~?]

Source: Internet
Author: User

  

Distance Last commit: >< has been in the past 1.5 months ...

Then go to see someone else rxdoi.

  

The gap is getting bigger ...

7.01

BZOJ1061 NOI 2008 Volunteers recruit employee byvoid stick Rod

The network stream feels strong, but it's hard to think of such a way

Some inequalities are processed into a number of plus and 0 equations, as each employee's working time is continuous.

So X[i] will only appear once in the equation of the start time, and the last moment of the end time appears in negative form once

Use the value on the right side of the equation to create an edge between the Yuanhui points, and then build the edge between the points and the points. W

T took six or seven times. Changed six or seven times ... Changed a lot like not open long long, the array is not open enough, can O (n) The edge I use O (nm) even ...

At last it seemed as if the cost flow had been wrongly written. TAT

  

   

?
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 #include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#define INF 10000000000000007#define maxn 1010#define maxm 10010#define maxe 25000#define ll long longusingnamespacestd;ll c[maxm],v[maxn],w[maxe],cst[maxe],dis[maxn];int n,m,s,t,e,a[maxm],b[maxm];intfa[maxe],next[maxe],link[maxn],son[maxe],rec[maxe],opt[maxn],pre[maxn];boolvis[maxn];voidadd(intx,inty,ll z,ll cost){    fa[++e]=y;next[e]=link[x];link[x]=e;w[e]=z;cst[e]=cost;son[e]=x;rec[e]=e+1;    fa[++e]=x;next[e]=link[y];link[y]=e;w[e]=0;cst[e]=-cost;son[e]=y;rec[e]=e-1;}boolspfa(){    for(inti=s;i<=t;i++) dis[i]=INF,vis[i]=true;    dis[s]=0;vis[s]=false;int head=0,tail=1;opt[1]=s;    while(head!=tail){        head=(head+1)%maxn;        for(intx=opt[head],i=link[x];i;i=next[i]) if(w[i]&&dis[x]+cst[i]<dis[fa[i]]){            dis[fa[i]]=dis[x]+cst[i];pre[fa[i]]=i;            if(vis[fa[i]]) tail=(tail+1)%maxn,opt[tail]=fa[i],vis[fa[i]]=false;        }        vis[opt[head]]=true;    }    if(dis[t]!=INF) returntrue;returnfalse;}ll MCMF(){    ll ans=0;    while (spfa()){        intu=t;ll mn=INF;        while(u!=s) mn=min(mn,w[pre[u]]),u=son[pre[u]];        u=t;        while(u!=s) w[pre[u]]-=mn,w[rec[pre[u]]]+=mn,ans+=mn*cst[pre[u]],u=son[pre[u]];    }    returnans;}intmain(){    scanf("%d%d",&n,&m);    memset(c,0,sizeof(c));    memset(v,0,sizeof(v));    for(inti=1;i<=n;i++) scanf("%lld",&v[i]);    for (inti=n+1;i>=1;i--) v[i]=v[i]-v[i-1];    for(inti=1;i<=m;i++) scanf("%d%d%lld",&a[i],&b[i],&c[i]);    s=0,t=n+2,e=0;    for(inti=1;i<=n+1;i++) if(v[i]>0) add(s,i,v[i],0);elseadd(i,t,-v[i],0);    for(inti=1;i<=m;i++) add(a[i],b[i]+1,INF,c[i]);    for (inti=2;i<=n+1;i++) add(i,i-1,INF,0);    printf("%lld",MCMF());    return0;}

"Can't continue the wave" BZ to do the title record [7.01~?]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.