Topic Link: bzoj3550
The main effect of the topic:
There are 3N number, you need to select some number, first of all, to ensure that any length of the interval of n, the number of selected <=k, and secondly to ensure that the number of the most selected.
Exercises
Simple shape
Set the number of times Xi is the number of I, and then limit it by the title. Oh, plus xi≤1.
You don't even have to have a dual.
#include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream
> #include <algorithm> using namespace std;
#define MAXN 1010 Const double INF=1E15;
const double eps=0.00000001;
int n,m;double A[MAXN][MAXN];
Double Myabs (double x) {return (x<0)?-x:x} void Pivot (int l,int e) {double tt=a[l][e];a[l][e]=1;
int i,j;
for (i=0;i<=n;i++) A[l][i]/=tt;
for (i=0;i<=m;i++) if (i!=l && myabs (a[i][e)) >eps) {double p=a[i][e];a[i][e]=0;
for (j=0;j<=n;j++) a[i][j]-=a[l][j]*p;
the bool Simplex () {while (1) {int i,l,e;l=e=0;
for (i=1;i<=n;i++) if (a[0][i]>eps &&!e) {e=i;break;}
Double Minn=inf;
if (!e) break;
for (i=1;i<=m;i++) if (a[i][e]>eps && a[i][0]/a[i][e]<minn) {minn=a[i][0]/a[i][e];l=i;}
if (!l) return false;
Pivot (l,e);
}return true; } INT Main () {//freopen ("a.in", "R", stdin);
Freopen ("A.out", "w", stdout);
int k,i,j,sum;
scanf ("%d%d", &n,&k);
sum=n*3;
for (i=1;i<=sum;i++) scanf ("%lf", &a[0][i));
for (i=1;i<=sum-n+1;i++) {a[i][0]=k;
for (j=1;j<=n;j++) a[i][i+j-1]=1;
} m=sum-n+1;n=sum;
for (i=1;i<=n;i++) a[++m][i]=1,a[m][0]=1;
if (simplex ()) printf ("%d\n", (int) (-a[0][0]+0.5));
else printf (" -1\n");
return 0; }