hdu 5697 刷题计划

类似最小乘积生成树那样。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <functional>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;


#define eps 1e-10
#define inf 0x3f3f3f3f
#define LL long long
#define pii pair<int, int>
#define MP make_pair
#define md (ll + rr >> 1)
#define ls i << 1
#define rs ls | 1
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define N 100010
#define M 400020

struct point{
	int x, y;
	point(int x = 0, int y = 0) : x(x), y(y) {}
	point operator - (const point &b) const {
		return point(x - b.x, y - b.y);
	}
	point operator + (const point &b) const {
		return point(x + b.x, y + b.y);
	}
};
LL cross(point a, point b){
	return 1LL * a.x * b.y - 1LL * a.y * b.x;
}

int n, m, sum;
int a[N], b[N], c[N];
point p[N];
LL dp[N], f[N], ans;
point gao(){
	p[0] = point(0, 0), dp[0] = 0;
	for(int i = 1; i <= sum; ++i) dp[i] = 1LL << 60;
	for(int i = 1; i <= n; ++i){
		for(int j = sum; j >= a[i]; --j){
			if(dp[j] > dp[j-a[i]] + f[i]){
				dp[j] = dp[j-a[i]] + f[i];
				p[j] = p[j-a[i]] + point(b[i], c[i]);
			}
		}
	}
	int ret = m; 
	LL tot = 1LL * p[ret].x * p[ret].y;
	for(int i = m; i <= sum; ++i) {
		if(dp[i] < dp[ret] || dp[i] == dp[ret] && 1LL * p[i].x * p[i].y < tot)
			ret = i, tot = 1LL * p[ret].x * p[ret].y;
	}
	ans = min(ans, tot);
	return p[ret];
}
void solve(point A, point B){
	for(int i = 1; i <= n; ++i)
		f[i] = 1LL * c[i] * (B.x - A.x) + 1LL * b[i] * (A.y - B.y);
	point C = gao();
	if(cross(B - A, C - A) >= 0)
		return ;
	solve(A, C);
	solve(C, B);
}
int main(){
	while(scanf("%d%d", &n, &m) != EOF){
		sum = 0;
		for(int i = 1; i <= n; ++i){
			scanf("%d%d%d", &a[i], &b[i], &c[i]);
			sum += a[i];
		}
		ans = 1LL << 60;
		for(int i = 1; i <= n; ++i)
			f[i] = b[i];
		point A = gao();

		for(int i = 1; i <= n; ++i)
			f[i] = c[i];
		point B = gao();
		
		solve(A, B);
		cout << ans << endl;
	}

	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值