九度OJ 教程103 广搜解决《珍惜现在,感恩生活》之内存超

本文探讨了如何通过优化内存使用和资源分配策略来提升程序性能。通过引入内存分配算法和资源管理技巧,实现了在有限资源下高效运行复杂任务的目标。

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

内存超



http://ac.jobdu.com/problem.php?cid=1040&pid=102


#include<stdio.h>
#include<string.h>
#define MAXS 105
#include<queue>;
using namespace std;
typedef struct E{
	int weight;
	int rest_money;
	int nrest[102];//rest[m]表示该E状态下第m种大米剩余的数量
}E;
typedef struct MICE{
	int cost;
	int weight;
}MICE;
MICE mi[102];
queue < E > Q;
int main()
{
	int C,a,b,m,n,i,maxw;
	E temp,now,spa;
	memset(&spa,0,sizeof(E));
	scanf("%d",&C);
	while(C--)
	{
		memset(mi,0,102*sizeof(int));
		temp=now=spa;
		while(Q.empty()==false)Q.pop();
		maxw=0;
		scanf("%d %d",&n,&m);
		now.rest_money=n;
		for(i=1;i<=m;i++)scanf("%d %d %d",&mi[i].cost,&mi[i].weight,&now.nrest[i]);
		Q.push(now);
		while(Q.empty()==false)
		{
			now=Q.front();
			Q.pop();
			for(i=1;i<=m;i++)
			{
				if(now.nrest[i]&&now.rest_money>=mi[i].cost)
				{
					temp=now;
					temp.rest_money-=mi[i].cost;
					temp.nrest[i]--;
					temp.weight+=mi[i].weight;
					Q.push(temp);
					if(maxw<temp.weight)maxw=temp.weight;
				}
			}//for
		}//while
		printf("%d\n",maxw);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值