背包--nkoj3609【USACO 2015 Dec Gold】Fruit Feast

解决USACO2015DecGold中关于贝西如何通过吃橘子派和柠檬派来达到最大饱度的问题。通过使用背包背包算法,在给定的饱度限制下,最大化饱度值。考虑喝水的影响,将其饱度减半。

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

【USACO 2015 Dec Gold】Fruit Feast

Description

Bessie has broken into Farmer John's house again! She has discovered a pile of lemons and a pile of oranges in the kitchen (effectively an unlimited number of each), and she is determined to eat as much as possible. 
Bessie has a maximum fullness of T (1≤T≤5,000,000). Eating an orange increases her fullness by A, and eating a lemon increases her fullness by B (1≤A,B≤T). Additionally, if she wants, Bessie can drink water at most one time, which will instantly decrease her fullness by half (and will round down). 
Help Bessie determine the maximum fullness she can achieve! 

贝西正在搞破坏,她在厨房里发现了一堆柠檬派和一堆橘子派,打算尽量多吃一点。 
贝西能够达到的最大饱度为T(1≤T≤5,000,000)。每一份橘子派会增加A的饱度,每一份柠檬派会增加B的饱度(1≤A,B≤T)。她可以在吃的过程中至多喝一次水,喝水之后她的饱度会减半(向下取整)。 
帮贝西算出她能够达到的最大饱度。 

Input

The first (and only) line has three integers T, A, and B. 

第一行三个整数T,A,B。 

Output

A single integer, representing the maximum fullness Bessie can achieve. 

输出一个整数,表示贝西可以达到的最大饱度。 

Sample Input

8 5 6

Sample Output

8

水题:不解释,背包背包

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
bool f[5000005];
int w[3];
int main(){
	int t,a,b,i,j;
	scanf("%d%d%d",&t,&a,&b);
	if(t%a==0||t%b==0){
		cout<<t;return 0;
	}
	w[1]=a;w[2]=b;
	f[0]=true;
	for(i=1;i<=2;i++){
		for(j=w[i];j<=t;j++){
			if(f[j-w[i]])f[j]=true;
		}
	}
	if(f[t]){
		cout<<t;
		return 0;
	}
	else{
		for(i=1;i<=t;i++){
			if(f[i])f[i/2]=true;
		}
	f[0]=false;
		for(i=1;i<=2;i++){
		for(j=w[i];j<=t;j++){
			if(f[j-w[i]])f[j]=true;
		}
	}
	}
	for(i=t;i>=0;i--){
		if(f[i]){
			cout<<i<<endl;
			return 0;
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值