3265: 志愿者招募加强版
2017-02-22 19:28
183 查看
3265: 志愿者招募加强版
Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 535 Solved: 285
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
3 32 3 4
1 1 2 2
1 2 3 5
1 3 3 2
Sample Output
14HINT
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;
}
相关文章推荐
- [BZOJ3265]志愿者招募加强版(单纯形)
- BZOJ 3265 志愿者招募(BZOJ 1061)加强版 && BZOJ 3112 [Zjoi2013]防守战线 单纯形
- bzoj 3265: 志愿者招募加强版 (单纯形)
- BZOJ 3265: 志愿者招募加强版 [单纯形法]
- 【bzoj3265】志愿者招募加强版 单纯形
- 【BZOJ3265】志愿者招募加强版 线性规划 单纯形法 对偶原理
- [BZOJ3265]志愿者招募加强版
- bzoj3265 志愿者招募加强版(线性规划)
- BZOJ 3265 志愿者招募加强版 单纯形
- bzoj 3265 志愿者招募加强版 (单纯形)
- [线性规划 对偶原理 单纯形] BZOJ 3265 志愿者招募加强版
- 【BZOJ3265】志愿者招募加强版【单纯形法】
- 【BZOJ1061/3265】[Noi2008]志愿者招募/志愿者招募加强版 单纯形法
- [单纯形+对偶] BZOJ3265: 志愿者招募加强版
- BZOJ_P3265 志愿者招募加强版(最小费用最大流)
- bzoj3265 志愿者招募加强版(单纯形)
- 【BZOJ】【P3265】【志愿者招募加强版】【题解】【单纯形法】
- bzoj1061、3265 志愿者招募【单纯形法】
- bzoj3265 志愿者招募加强版
- BZOJ.3265.志愿者招募加强版(费用流SPFA)