POJ 1276 Cash Machine

Description

A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a supply of nk bills. For example,

N=3, n1=10, D1=100, n2=4, D2=50, n3=5, D3=10

means the machine has a supply of 10 bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each.

Call cash the requested amount of cash the machine should deliver and write a program that computes the maximum amount of cash less than or equal to cash that can be effectively delivered according to the available bill supply of the machine.

Notes:
@ is the symbol of the currency delivered by the machine. For instance, @ may stand for dollar, euro, pound etc.

Input

The program input is from standard input. Each data set in the input stands for a particular transaction and has the format:

cash N n1 D1 n2 D2 ... nN DN

where 0 <= cash <= 100000 is the amount of cash requested, 0 <=N <= 10 is the number of bill denominations and 0 <= nk <= 1000 is the number of available bills for the Dk denomination, 1 <= Dk <= 1000, k=1,N. White spaces can occur freely between the numbers in the input. The input data are correct.

Output

For each set of data the program prints the result to the standard output on a separate line as shown in the examples below.

Sample Input

735 3  4 125  6 5  3 350
633 4  500 30  6 100  1 5  0 1
735 0
0 3  10 100  10 50  10 10

Sample Output

735
630
0
0
 
背包问题,大意是有各种不同面值的货币,每种面值的货币有有限的数量,把这些货币组成最多但不超过cash的数。
从面值从小到大做多重背包 。从cash开始dp,rcnt记录当前总价时的剩余的当前价值货币的个数。
 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef struct node
{
	int c,p;
}q;
bool cmp(q a,q b)
{
	return a.p<b.p;
}
char dp[100001];
int rcnt[100001];
int main()
{
	q p[11];
	int cash,n,i,j;
	
	while(scanf("%d%d",&cash,&n)!=EOF)
	{
		if(!n)
		{
		printf("0\n");
		continue;
		}
		for(i=0;i<n;i++)
		
			scanf("%d%d",&p[i].c,&p[i].p);
	
		p[n].c=0;
		if(!cash)
		{
			printf("0\n");
			continue;
		}
			sort(p,p+n,cmp);
			memset(dp,0,sizeof(dp));
			memset(rcnt,0,sizeof(rcnt));

			dp[cash]=1;
		
			rcnt[cash]=p[0].c;
		
		for(i=0;i<n;i++)
		{
			for(j=cash;j>=p[i].p;j--)
			{
				if(dp[j])
				{
					if(rcnt[j]&&!dp[j-p[i].p])
					{
						rcnt[j-p[i].p]=rcnt[j]-1;
						dp[j-p[i].p]=1;
					}
					rcnt[j]=p[i+1].c;
				}
			}
		}
		 i=0;  		while(dp[i]==0)  		{  			 i++;  		} 		 printf("%d\n",cash-i);			}
	return 0;
}

基于NSGA-III算法求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文围绕基于NSGA-III算法的微电网多目标优化调度展开研究,重点介绍了如何利用该先进多目标进化算法解决微电网系统中多个相互冲突的目标(如运行成本最小化、碳排放最低、供电可靠性最高等)的协同优化问题。文中结合Matlab代码实现,详细阐述了NSGA-III算法的基本原理、在微电网调度模型中的建模过程、约束条件处理、目标函数设计以及仿真结果分析,展示了其相较于传统优化方法在求解高维、非线性、多目标问题上的优越性。同时,文档还提供了丰富的相关研究案例和技术支持背景,涵盖电力系统优化、智能算法应用及Matlab仿真等多个方面。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源优化领域的工程技术人员;尤其适合正在进行微电网调度、多目标优化算法研究或撰写相关论文的研究者。; 使用场景及目标:①掌握NSGA-III算法的核心思想及其在复杂能源系统优化中的应用方式;②学习如何构建微电网多目标调度模型并利用Matlab进行仿真求解;③为科研项目、毕业论文或实际工程提供算法实现参考和技术支撑。; 阅读建议:建议读者结合文中提供的Matlab代码实例,逐步调试运行并深入理解算法流程与模型构建细节,同时可参考文档中列出的其他优化案例进行横向对比学习,以提升综合应用能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值