HDU-1114 Piggy-Bank —DP最小装载

本文介绍了一种算法,用于解决一个有趣的问题:确定一个装满未知数量硬币的猪存钱罐的最小可能价值。通过使用完全背包问题的变体,我们能够找到在给定总重量下硬币组合的最小价值,避免了盲目打破存钱罐的风险。

Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to pay everything that needs to be paid.

But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing two integers E and F. They indicate the weight of an empty pig and of the pig filled with coins. Both weights are given in grams. No pig will weigh more than 10 kg, that means 1 <= E <= F <= 10000. On the second line of each test case, there is an integer number N (1 <= N <= 500) that gives the number of various coins used in the given currency. Following this are exactly N lines, each specifying one coin type. These lines contain two integers each, Pand W (1 <= P <= 50000, 1 <= W <=10000). P is the value of the coin in monetary units, W is it’s weight in grams.
Output
Print exactly one line of output for each test case. The line must contain the sentence “The minimum amount of money in the piggy-bank is X.” where X is the minimum amount of money that can be achieved using coins with the given total weight. If the weight cannot be reached exactly, print a line “This is impossible.”.
Sample Input

3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4

Sample Output

The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.

题意描述:
给出t组数据每组先给出e和f,分别表示猪猪最初重量和最终重量,然后给出一个n之后再给出n个p和w,p和w分别表示硬币的价值和重量,均小于10000。然后求出猪猪中装满最小能装的价值是多少。

解题思路:
完全背包模板把max改成min就可以了。

AC代码:

#include<cstdio>
#include<algorithm>
using namespace std;

int main(void)
{
	int i,j,dp[10010],inf=99999999;
	int t,e,f,n,v,p[510],w[510];
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&e,&f);
		v=f-e;
		scanf("%d",&n);
		for(i=0;i<n;i++)
			scanf("%d%d",&p[i],&w[i]);
		for(i=0;i<=v;i++)
			dp[i]=inf;
		dp[0]=0;//解释:由于数组初始化为inf
				// 又因p<=10000;p<inf。 
		for(i=0;i<n;i++)
			for(j=w[i];j<=v;j++)
					dp[j]=min(dp[j],dp[j-w[i]]+p[i]);
		if(dp[v]<inf) 
			printf("The minimum amount of money in the piggy-bank is %d.\n",dp[v]);
		else
			printf("This is impossible.\n");
	}
	return 0;
 } 
**高校专业实习管理平台设计与实现** 本设计项目旨在构建一个服务于高等院校专业实习环节的综合性管理平台。该系统采用当前主流的Web开发架构,基于Python编程语言,结合Django后端框架与Vue.js前端框架进行开发,实现了前后端逻辑的分离。数据存储层选用广泛应用的MySQL关系型数据库,确保了系统的稳定性和数据处理的效率。 平台设计了多角色协同工作的管理模型,具体包括系统管理员、院系负责人、指导教师、实习单位对接人以及参与实习的学生。各角色依据权限访问不同的功能模块,共同构成完整的实习管理流程。核心功能模块涵盖:基础信息管理(如院系、专业、人员信息)、实习过程管理(包括实习公告发布、实习内容规划、实习申请与安排)、双向反馈机制(单位评价与学生反馈)、实习支持与保障、以及贯穿始终的成绩评定与综合成绩管理。 在技术实现层面,后端服务依托Django框架的高效与安全性构建业务逻辑;前端界面则利用Vue.js的组件化特性与LayUI的样式库,致力于提供清晰、友好的用户交互体验。数据库设计充分考虑了实习管理业务的实体关系与数据一致性要求,并保留了未来功能扩展的灵活性。 整个系统遵循规范的软件开发流程,从需求分析、系统设计、编码实现到测试验证,均进行了多轮迭代与优化,力求在功能完备性、系统性能及用户使用体验方面达到较高标准。 **核心术语**:实习管理平台;Django框架;MySQL数据库;Vue.js前端;Python语言。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
在电磁散射与雷达技术的研究中,涉及粗糙表面电磁特性模拟的核心概念包括统计参数化建模方法、不同电场矢量方向的极化模式、特定方向的能量反射现象、理想化波前模型以及具有随机起伏特征的界面。以下是对这些要点的系统阐述: 统计参数化建模是一种基于表面统计特征描述其不规则性的电磁散射计算方法,尤其适用于均方根高度较小的粗糙界面在微波至毫米波频段的散射特性分析。 水平极化与垂直极化分别指电场矢量平行于地面和垂直于地面的振动状态。在雷达探测中,采用不同的极化模式有助于提升目标辨识度并抑制环境干扰。 当电磁波与物体相互作用时,部分能量沿接近入射方向返回,这种现象称为反向散射。其在雷达系统的探测灵敏度与目标特征分析中具有关键作用。 平面波是在均匀介质中传播的理想波型,其电场与磁场分布保持一致的相位关系,常作为理论简化模型用于电磁问题的解析与数值计算。 粗糙界面指具有随机起伏特征的表面,其不规则程度可通过均方根高度进行量化。这种结构特性会改变电磁波的传播路径与能量分布,进而影响信号的接收与处理。 相关压缩文件可能包含了实现上述建模方法的程序代码,通常采用数值计算语言编写,用于模拟不同极化状态下粗糙表面对平面波的反向散射响应。通过此类仿真,能够预测各类场景下的散射参数,为雷达系统设计与遥感数据解译提供理论依据。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值