The main topic: given a length of 3n interval, the need to select some number, and any length of n interval of the maximum number of k, the maximum number of selected numbers
Simplex directly engage in
Note that a number can only be selected once, so add xi<=1 to this binding condition
Do not understand 3n and k<=10 is why ...
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define EPS 1e-7#define INF 1e10using namespace Std;int n,m,k;namespace linear_programming{double A[1210][ 610],b[1210],c[610],v;void Pivot (int l,int e) {int i,j;b[l]/=a[l][e];for (i=1;i<=n;i++) if (i!=e) a[l][i]/=a[l][e]; A[l][e]=1/a[l][e];for (i=1;i<=m;i++) if (I!=l&&fabs (A[i][e]) >eps) {b[i]-=a[i][e]*b[l];for (j=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 (i=1;i<=n;i++) if (i!=e) c[i]-=c[e]*a[l][i];c[e]=-c[e]*a[l][e];} Double Simplex () {int I,l,e;while (1) {for (i=1;i<=n;i++) if (c[i]>eps) break;if ((e=i) ==n+1) return v;double temp= Inf;for (i=1;i<=m;i++) if (a[i][e]>eps && b[i]/a[i][e]<temp) temp=b[i]/a[i][e],l=i;if (Temp==INF) return INF; Pivot (l,e);}}} int main () {using namespace Linear_programming;int i,j;cin>>n>>k;for (i=1;i<=n*3;i++) scanf ("%lf", &c[i]); for (i=1;i+n-1<=n*3;i++) {b[++m]=k;for (j=i;j<=i+n-1;j++) a[m][j]=1;} for (i=1;i<=n*3;i++) {b[++m]=1; A[m][i]=1;} N*=3;double Ans=simplex (); Cout<<int (ans+0.5) <<endl;return 0;}
Bzoj 3550 ONTAK2010 Vacation simplex