BZOJ1061: [Noi2008] Volunteer recruitment

Source: Internet
Author: User

Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1061

1061: [Noi2008] Volunteers recruitment time limit:20 Sec Memory limit:162 MB
submit:3878 solved:2367
[Submit] [Status] [Discuss] Description after the successful bid, Bubu after unremitting efforts, and finally become the Director of the Human Resources Department of the Organization of the Olympic Games. Bubu has just come into a dilemma: recruiting short-term volunteers for the upcoming new Olympic project. It is estimated that the project will take n days to complete, with the first day I need an AI person at least. Bubu learned by understanding that there are altogether m-type volunteers can recruit. In which class I can work from Si days to ti days, the recruitment fee is per person ci yuan. In order to do his job well, Bubu hopes to recruit enough volunteers with as little money as possible, but this is not his specialty! So Bubu found you, I hope you help him design an optimal recruitment program. The first line of Input contains two integers n, M, indicating the number of days to complete the project and the types of volunteers that can be recruited. The next line contains n non-negative integers, representing at least the number of volunteers needed per day. The next M-line contains three integers of Si, Ti, Ci, meaning as described above. For the sake of convenience, we can assume that the number of each type of volunteer is infinitely large. Output

Contains only an integer representing the total cost of the optimal scheme you have designed.

Sample Input3 3
2 3 4
1 2 2
2 3 5
3 3 2Sample Output -HINT

1≤n≤1000,1≤m≤10000, the other data involved in the topic are not more than 2^31-1.

God's problem. Can't write at all.

or worship this article: https://www.byvoid.com/blog/noi-2008-employee/

#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 1005#define MAXM 10005using namespace Std;const int Inf=0x7fffffff;int ans,n,m,tot,s,t,h[maxn],way[maxm*4],next[maxm*4],ww[maxm*4],cap[maxm*4]  , A[maxn],pre[maxn];int read () {int X=0,f=1;char ch; For (Ch=getchar ();ch< ' 0 ' | |  Ch> ' 9 '; Ch=getchar ()) if (ch== '-') f=-1;  for (; ch>= ' 0 ' &&ch<= ' 9 '; Ch=getchar ()) x=x*10+ch-' 0 '; return x*f;} void Add (int x,int y,int w,int c) {way[++tot]=y;next[tot]=h[x];h[x]=tot;ww[tot]=w;cap[tot]=c;} void Insert (int x,int y,int w,int c=inf) {Add (x,y,w,c); add (y,x,-w,0);}  int Head,tail,d[maxn+10],dist[maxn];bool V[maxn];bool SPFA () {memset (v,0,sizeof (v)); v[s]=1;pre[s]=-1;  for (int i=0;i<=t;i++) dist[i]=inf;dist[s]=0;  Head=0;tail=1;d[0]=s;    while (head!=tail) {int x=d[head];head++;if (HEAD&GT;MAXN) head=0; for (int j=h[x];j;j=next[j]) if (Cap[j]&&dist[way[j]]>dist[x]+ww[j]) {dist[way[j]]=dist[x]+ww[j];p Re[way [J]]    =j; if (!v[way[j]]) {v[way[j]]=1;d[tail++]=way[j];if (TAIL&GT;MAXN) tail=0;  }} v[x]=0; } return Dist[t]!=inf;}  int find () {int delt=inf,x=0;  for (int j=t;j!=s;j=way[pre[j]^1]) {delt=min (delt,cap[pre[j]]);  } for (int j=t;j!=s;j=way[pre[j]^1]) {x=x+delt*ww[pre[j]];cap[pre[j]]-=delt;cap[pre[j]^1]+=delt; } return x;}  int main () {n=read (); M=read (); tot=1;  for (int i=1;i<=n;i++) a[i]=read ();    for (int i=1,x,y,z;i<=m;i++) {x=read (); Y=read (); Z=read ();  Insert (X,Y+1,Z);  } s=0;t=n+2;    for (int i=1;i<=n+1;i++) {int x=a[i]-a[i-1];    if (x>=0) insert (S,I,0,X);    else insert (i,t,0,-x);  if (i>1) insert (i,i-1,0);  } while (SPFA ()) Ans+=find ();  printf ("%d\n", ans); return 0;}

BZOJ1061: [Noi2008] Volunteer recruitment

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.