牛客假日团队赛5.E

博客围绕牛客网的一道题目展开,Bessie饮食有卡路里限制,面对多桶不同卡路里的饲料,需找出不超限制的最大卡路里组合。该问题本质是01背包问题,物体容量和价值均为卡路里数,最后给出了AC代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

牛客假日团队赛5.E
链接:https://ac.nowcoder.com/acm/contest/984/E
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
Bessie is on a diet where she can eat no more than C (10 ≤ C ≤ 35,000) calories per day. Farmer John is teasing her by putting out B (1 ≤ B ≤ 21) buckets of feed, each with some (potentially non-unique) number of calories (range: 1…35,000). Bessie has no self-control: once she starts on a feed bucket, she consumes all of it.
Bessie is not so good at combinatorics. Determine the optimal combination of feed buckets that gives Bessie as many calories without exceeding the limit C.
As an example, consider a limit of 40 calories and 6 buckets with 7, 13, 17, 19, 29, and 31 calories. Bessie could eat 7 + 31 = 38 calories but could eat even more by consuming three buckets: 7 + 13 + 19 = 39 calories. She can find no better combination.
输入描述:

Line 1: Two space-separated integers: C and B
Line 2: B space-separated integers that respectively name the number of calories in bucket 1, 2, etc.

输出描述:

Line 1: A single line with a single integer that is largest number of calories Bessie can consume and still stay on her diet.

示例1
输入

40 6
7 13 17 19 29 31

输出

39


思路:其实就是一个01背包问题,只不过一个物体的容量和价值是一样的,都是其卡路里数。在卡路里有范围的情况下求出最大的卡路里值。

AC代码:

#include<bits/stdc++.h>
#define INF 0x3F3F3F3F
#define endl '\n'
#define pb push_back
#define css(n) cout<<setiosflags(ios::fixed)<<setprecision(n); 
#define sd(a) scanf("%d",&a)
#define sld(a) scanf("%lld",&a)
#define m(a,b) memset(a,b,sizeof a)
#define p_queue priority_queue
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,m;
int t;
double a,b;
int dp[35005];
int arr[25];
int main()
{
	 scanf("%d%d",&n,&m);
	 //n是最大的卡路里数,m是桶数。
	 memset(dp,0,sizeof(dp));
	 for(int i=1;i<=m;i++)
	 {
	 	scanf("%d",&arr[i]);
	  } 
	  for(int i=1;i<=m;i++)
	  {
	  	for(int j=n;j>=arr[i];j--)
	  	{
	  		dp[j]=max(dp[j],dp[j-arr[i]]+arr[i]);
		  }
	  }
	  printf("%d\n",dp[n]);
	return 0;
} 
内容概要:本文深入探讨了DevOps流程落地中自动化测试与监控体系的构建,强调二者是保障软件质量和系统稳定性的重要支柱。自动化测试涵盖从单元测试到端到端测试的全流程自动化,而监控体系则通过实时采集和分析系统数据,及时发现并解决问题。文章介绍了测试金字塔模型的应用、监控指标的分层设计、测试与生产环境的一致性构建以及告警策略的精细化设置等核心技巧。此外,还提供了基于Python和Prometheus的具体代码案例,包括自动化接口测试脚本和监控指标暴露的实现,展示了如何在实际项目中应用这些技术和方法。 适合人群:对DevOps有一定了解,从事软件开发、运维或测试工作的技术人员,特别是那些希望提升自动化测试和监控能力的从业者。 使用场景及目标:①高并发业务系统中,模拟大规模用户请求,验证系统抗压能力和稳定性;②关键业务流程保障,确保金融交易、医疗数据处理等敏感业务的合规性和可追溯性;③微服务架构系统下,通过契约测试和分布式链路追踪,保证服务间的兼容性和故障快速定位。 阅读建议:本文不仅提供了理论指导,还有详细的代码示例,建议读者结合自身项目的实际情况,逐步实践文中提到的技术和方法,特别是在构建自动化测试框架和监控系统时,关注环境一致性、测试覆盖率和性能指标等方面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值