3265: 志愿者招募加强版

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值