2019 GDUT Rating Contest #I 题解

                           2019 GDUT Rating Contest #I 题解
                                                   A题

题面:

Farmer John is considering a change in how he allocates buckets for milking his cows. He thinks this will ultimately allow him to use a small number of total buckets, but he is not sure how many exactly. Please help him out! Farmer John has N cows (1≤N≤100)(1≤N≤100), conveniently numbered 1…N1…N. The ithith cow needs to be milked from time sisi to time titi, and requires bibi buckets to be used during the milking process. Several cows might end up being milked at the same time; if so, they cannot use the same buckets. That is, a bucket assigned to cow i′si′s milking cannot be used for any other cow's milking between time sisi and time titi. The bucket can be used for other cows outside this window of time, of course. To simplify his job, FJ has made sure that at any given moment in time, there is at most one cow whose milking is starting or ending (that is, the sisi's and ti's are all distinct).

FJ has a storage room containing buckets that are sequentially numbered with labels 11, 22, 33, and so on. In his current milking strategy, whenever some cow (say, cow ii) starts milking (at time sisi), FJ runs to the storage room and collects the bi buckets with the smallest available labels and allocates these for milking cow ii.

Please determine how many total buckets FJ would need to keep in his storage room in order to milk all the cows successfully.

Input

The first line of input contains NN. The next NN lines each describe one cow, containing the numbers sisi, titi, and bibi, separated by spaces. Both sisi and titi are integers in the range 1…10001…1000, and bibi is an integer in the range 1…101…10.

Output

Output a single integer telling how many total buckets FJ needs.

Example

input

3
4 10 1
8 13 3
2 6 2
output

4

Note

In this example, FJ needs 4 buckets: He uses buckets 1 and 2 for milking cow 3 (starting at time 2). He uses bucket 3 for milking cow 1 (starting at time 4). When cow 2 arrives at time 8, buckets 1 and 2 are now available, but not bucket 3, so he uses buckets 1, 2, and 4.

题面描述:

             题目讲述的是,有n头奶牛,每头奶牛都有对应的时间去被挤牛奶以及需要盛奶牛的木桶数,如果同一个时间段有多头奶牛被挤牛奶的话,那么一个木桶只能盛一头奶牛的牛奶,题目问我们最少用多少个木桶可以满足奶牛的需求。

题目分析:

             由于题目给的数据比较小,因此我们对于每头奶牛被挤牛奶的时间段均加上木桶数,然后求出每个时间段需要的最大木桶数即为最终答案。

代码:

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define reg register
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define lowbit(x) (x&(-x))
using namespace std;
const int Maxn=105;
const int Maxst=1005;
int cnt[Maxst];
int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		memset(cnt,0,sizeof(cnt));
		int ans=0;
		for (reg int i=1;i<=n;i++)
		{
			int s,t,b;
			scanf("%d%d%d",&s,&t,&b);
			for (reg int j=s;j<=t;j++)
			{
				cnt[j]+=b;
				ans=max(ans,cnt[j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

                                                   B题

题面:

For his favorite holiday, Farmer John wants to send presents to his friends. Since he isn't very good at wrapping presents, he wants to enlist the help of his cows. As you might expect, cows are not much better at wrapping presents themselves, a lesson Farmer John is about to learn the hard way.

Farmer John's NN cows (1≤N≤1041≤N≤104) are all standing in a row, conveniently numbered 1…N1…N in order. Cow ii has skill level sisi at wrapping presents. These skill levels might vary quite a bit, so FJ decides to combine his cows into teams. A team can consist of any consecutive set of up to KK cows (1≤K≤1031≤K≤103), and no cow can be part of more than one team. Since cows learn from each-other, the skill level of each cow on a team can be replaced by the skill level of the most-skilled cow on that team.

Please help FJ determine the highest possible sum of skill levels he can achieve by optimally forming teams.

Input

The first line of input contains NN and KK. The next NN lines contain the skill levels of the NN cows in the order in which they are standing. Each skill level is a positive integer at most 105105.

Output

Please print the highest possible sum of skill levels FJ can achieve by grouping appropriate consecutive sets of cows into teams.

Example

input

7 3
1
15
7
9
2
5
10
output

84

Note

In this example, the optimal solution is to group the first three cows and the last three cows, leaving the middle cow on a team by itself (remember that it is fine to have teams of size less than KK). This effectively boosts the skill levels of the 7 cows to 15, 15, 15, 9, 10, 10, 10, which sums to 84.

题面描述:

            这个题目讲述的是,输入n头奶牛的技巧值,然后可以将这些奶牛分成若干个组,每个组的奶牛数不超过k头,每组的奶牛经过互相学习,每头奶牛的技巧值均等于这头奶牛所在该组技巧值最高的奶牛的技巧值,而且奶牛的输入顺序不能够打乱,分为一组的奶牛必须是连续的奶牛,然后问我们怎么分组才能使得所有奶牛的技巧总和最大。

题目分析:

            这是一道线型DP的题目,我们设置一个DP数组,dp[i]表示前面的i头奶牛通过适当的分组所得的最大技巧值总和。

            首先我们从1到n枚举n头奶牛,然后我们需要枚举当前最后一组有多少头奶牛,假设当前最后一组有j头奶牛,那么dp[i]很明显就等于dp[i-j]再加上最后一组中技巧值最大的奶牛的技巧值乘以最后一组的奶牛个数。

            我们在求解最后一组奶牛最大技巧值的时候,如果我们再用一个循环去找出最大值的话,那么三重循环很明显会超时,其实我们可以枚举j从1到min(i,k),最后一组的奶牛数目从小到大枚举,这里注意的是,最后一组无论如何都要包括第i头奶牛,其实我们会发现这个过程已经从i枚举到i-j+1,刚好枚举完最后一组的所有奶牛,因此用一个变量记录枚举当中奶牛最大的技巧值即可,然后按上面的状态转移方程求出dp[i]即可,最后答案便为dp[n]。

代码:

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define reg register
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define lowbit(x) (x&(-x))
using namespace std;
const int Maxn=1e4+5;
const int Maxk=1005;
int skill[Maxn],dp[Maxn];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for (reg int i=1;i<=n;i++) scanf("%d",&skill[i]);
	for (reg int i=1;i<=n;i++)
	{
		int maxs=-1;
		for (reg int j=1;j<=min(k,i);j++)
		{
			maxs=max(maxs,skill[i-j+1]);
			dp[i]=max(dp[i],dp[i-j]+maxs*j);
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

 

                                                   C题

题面:

With plenty of free time on their hands (or rather, hooves), the cows on Farmer

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值