您的位置:首页 > 其它

3265: 志愿者招募加强版

2017-02-22 19:28 183 查看

3265: 志愿者招募加强版

Time Limit: 20 Sec  Memory Limit: 512 MB
Submit: 535  Solved: 285

[Submit][Status][Discuss]

Description



Input



Output



Sample Input

3 3

2 3 4

1 1 2 2

1 2 3 5

1 3 3 2

Sample Output

14

HINT



Source

单纯形

[Submit][Status][Discuss]


这是一个明显的线性规划模型,有种叫做单纯形的算法可以解决这类问题接链开打击点

具体的就看论文吧,这里只作一些笔记



#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

const int maxn = 1010;
const int maxm = 10010;
typedef double DB;
typedef long long LL;
const DB EPS = 1E-7;
const DB INF = 1E16;

DB A[maxm][maxn],b[maxn],c[maxm];
int n,m;

int getint()
{
char ch = getchar(); int ret = 0;
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <= '9')
ret = ret * 10 + ch - '0',ch = getchar();
return ret;
}

DB Pivot(int l,int e)
{
DB *_a = A[l],tmp = _a[e];
c[l] /= tmp; _a[e] = 1.00 / tmp;
for (int i = 1; i <= n; i++) if (i != e) _a[i] /= tmp;
for (int i = 1; i <= m; i++)
if (i != l && fabs(A[i][e]) > EPS)
{
DB *a = A[i]; tmp = a[e];
for (int j = 1; j <= n; j++)
if (j != e) a[j] -= _a[j] * tmp;
a[e] = -tmp * _a[e]; c[i] -= tmp * c[l];
}
tmp = b[e]; b[e] = -tmp * _a[e];
for (int i = 1; i <= n; i++) if (i != e) b[i] -= tmp * _a[i];
return tmp * c[l];
}

DB Work()
{
DB ret = 0;
for (;;)
{
int l,e = 0; DB tmp = INF;
for (int i = 1; i <= n; i++)
if (b[i] > EPS) {e = i; break;}
if (!e) return ret;
for (int i = 1; i <= m; i++)
if (A[i][e] > EPS && c[i] / A[i][e] < tmp)
tmp = c[i] / A[i][e],l = i;
if (tmp == INF) return INF;
ret += Pivot(l,e);
}
}

int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif

n = getint(); m = getint();
for (int i = 1; i <= n; i++) b[i] = getint();
for (int j = 1; j <= m; j++)
{
int k = getint(); DB *a = A[j];
while (k--)
{
int L = getint(),R = getint();
for (int i = L; i <= R; i++) a[i] = 1;
}
c[j] = getint();
}
cout << (LL)(Work() + 0.5) << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: