6989: Air Cownditioning II

题目描述

With the hottest recorded summer ever at Farmer John's farm, he needs a way to cool down his cows. Thus, he decides to invest in some air conditioners.

Farmer John's N cows (1≤N≤20) live in a barn that contains a sequence of stalls in a row, numbered 1…100. Cow i occupies a range of these stalls, starting from stall si and ending with stall ti. The ranges of stalls occupied by different cows are all disjoint from each-other. Cows have different cooling requirements. Cow i must be cooled by an amount ci, meaning every stall occupied by cow i must have its temperature reduced by at least ci units.

The barn contains M air conditioners, labeled 1…M (1≤M≤10). The i-th air conditioner costs mi units of money to operate (1≤mi≤1000) and cools the range of stalls starting from stall ai and ending with stall bi. If running, the i-th air conditioner reduces the temperature of all the stalls in this range by pi (1≤pi≤106). Ranges of stalls covered by air conditioners may potentially overlap.

Running a farm is no easy business, so FJ has a tight budget. Please determine the minimum amount of money he needs to spend to keep all of his cows comfortable. It is guaranteed that if FJ uses all of his conditioners, then all cows will be comfortable.

农夫约翰的农场有史以来最热的夏天,他需要一种方法来冷却他的牛。因此,他决定投资一些空调。农民约翰的 N 头奶牛(1≤ N ≤20头)生活在一个谷仓里,这个谷仓里有一排排的牛栏,编号为1... 100。牛 i 占据了这些摊位的范围,从摊位 si 开始,以摊位 ti 结束。不同的奶牛所占据的牛栏的范围都是相互脱节的。奶牛有不同的冷却要求。奶牛的体温必须降低一个单位,这意味着每一个被奶牛占据的隔间的温度必须至少降低一个单位。谷仓内有 M 台空调,标记为1... M (1≤ M ≤10)。第四台空调运行成本微小的单位(1≤ mi ≤1000)和冷却的摊位范围从摊位艾,以摊位双结束。如果运行,第四台空调降低所有在这个范围内的停机温度的 π (1≤ pi ≤106)。空调机所覆盖的档位范围可能会重叠。经营农场不是一件容易的事,所以 FJ 的预算很紧张。请确定他需要花费的最低金额,以保持他所有的牛舒适。这是保证,如果 FJ 使用他所有的护发素,那么所有的奶牛将是舒适的。

输入

The first line of input contains N and M.

The next N lines describe cows. The i-th of these lines contains si, ti, and ci.

The next M lines describe air conditioners. The i-th of these lines contains ai, bi, pi, and mi.

For every input other than the sample, you can assume that M=10.

第一行输入包含 N 和 M。

接下来的 N 行描述了奶牛。这些行的 i-th 包含 si、 ti 和 ci。

接下来的 M 行描述空调。这些线的 i-th 包含 ai,bi,pi 和 mi。

对于除样本以外的每个输入,可以假设 M = 10。

输出

Output a single integer telling the minimum amount of money FJ needs to spend to operate enough air conditioners to satisfy all his cows (with the conditions listed above).

输出一个单一的整数,表示 FJ 需要花费的最小金额,以操作足够的空调,以满足他所有的奶牛(与上面列出的条件)。

样例输入输出

样例输入 #1

2 4
1 5 2
7 9 3
2 9 2 3
1 6 2 8
1 2 4 2
6 9 1 5

样例输出 #1

10

样例说明 #1

One possible solution that results in the least amount of money spent is to select those that cool the intervals [2,9], [1,2], and [6,9], for a cost of 3+2+5=10.

一种花费最少金钱的可能解决方案是选择那些冷却区间 [2,9]、[1,2] 和 [6,9] 的解决方案,成本为 3+2+5=10 。

题目太长,只能借助翻译器了,有些语言不通顺的地方请谅解


分析

使用差分+dfs


代码
#include<bits/stdc++.h>
using namespace std;

const int maxn=100+10;
const int inf=2e9;
int n,m,ans=inf,k;
struct cows{
	int s,t,c;
	inline void input(){
		scanf("%d%d%d",&s,&t,&c);
	}
}a[maxn];
struct air{
	int st,ed,p,m;
	inline void input(){
		scanf("%d%d%d%d",&st,&ed,&p,&m);
	}
}cd[maxn];
int cnt[maxn];
inline void dfs(int x){
	if(x==m+1){
		bool flag=true;
		for(int i=1;i<=n;i++){
			for(int j=a[i].s;j<=a[i].t;j++){
				if(cnt[j]<a[i].c){
					flag=false;
					break;
				}
			} 
			if(!flag)break;
		}
		if(flag)ans=min(ans,k);
		return ;
	}
	for(int i=0;i<=1;i++){
		if(i==0){
			dfs(x+1);
			continue;
		}
		k+=cd[x].m;
		for(int j=cd[x].st;j<=cd[x].ed;j++)cnt[j]+=cd[x].p;
		dfs(x+1);
		k-=cd[x].m;
		for(int j=cd[x].st;j<=cd[x].ed;j++)cnt[j]-=cd[x].p;
	} 
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)a[i].input();
	for(int i=1;i<=m;i++)cd[i].input();
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

给个点赞和关注支持一下吧

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值