1061: [Noi2008] Volunteers recruitment time limit:20 Sec Memory limit:162 MB
submit:3975 solved:2421
[Submit] [Status] [Discuss] Description
After the successful bid, Bubu after unremitting efforts, and finally become the head of the organization's human resources department. 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.
I have seen the simplex method before, ( also spoken at noon )
I looked it over again tonight.
Resources:
1. Introduction to Algorithms 29 chapters
2.http://blog.csdn.net/fuxey/article/details/51039914
3.http://blog.csdn.net/popoqqq/article/details/44310605
You want to add
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;Const intm=10005, n=1005, inf=1e9;Const Doubleeps=1e-6; inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intn,m,v;DoubleA[m][n],b[m],c[n];voidPivotintLinte) {B[l]/=A[l][e]; for(intj=1; j<=n;j++)if(j!=e) a[l][j]/=A[l][e]; A[l][e]=1/A[l][e]; for(intI=1; i<=m;i++)if(I!=l&&fabs (a[i][e]) >0) {B[i]-=a[i][e]*B[l]; for(intj=1; j<=n;j++)if(j!=e) a[i][j]-=a[i][e]*A[l][j]; A[i][e]=-a[i][e]*A[l][e]; } v+=c[e]*B[l]; for(intj=1; j<=n;j++)if(j!=e) c[j]-=c[e]*A[l][j]; C[e]=-c[e]*A[l][e]; //swap (b[l],n[e])}Doublesimplex () { while(true){ intE=0, l=0; for(e=1; e<=n;e++)if(c[e]>eps) Break; if(e==n+1)returnv; Doublemn=INF; for(intI=1; i<=m;i++) if(A[i][e]>eps&&mn>b[i]/a[i][e]) mn=b[i]/a[i][e],l=i; if(Mn==inf)returnINF;//unboundedpivot (l,e); }}intMain () {n=read (); m=read (); for(intI=1; i<=n;i++) c[i]=read (); for(intI=1; i<=m;i++){ intS=read (), t=read (); for(intj=s;j<=t;j++) a[i][j]=1; B[i]=read (); } printf ("%d",(int) (simplex () +0.5));}
Bzoj 1061: [Noi2008] Volunteer recruitment [simplex method]