动态规划 HDU 2546 饭卡

HDU2546.饭卡动态规划(01背包:动态规划分支限界回溯 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 Input 多组数据。对于每组数据: 第一行为正整数n,表示菜的数量。n<=1000。 第二行包括n个正整数,表示每种菜的价 阅读详情

        在acm群里看到了这样的一个题目,拿过来看了一下,感觉还蛮有意思的,题目大意是饭卡上有m余额,但是学校有个规定,饭卡余额少于5元就不能买东西,现在有n件商品,每件商品都有一个价格。要求买好商品后余额最少。

        题目链接   HDU 2546 饭卡

        看到题目就想到了背包问题,在一个m-5的背包里尽量装满东西,装满后放最后一个物品,解肯定在放完这个物品之后。 最直接的想法就是对放的最后这个物品进行枚举,然后用余下的物品去装m-5的背包,尽量装满。得到的最小值就是答案。当然还要考虑余额小于5元的情况,如果小于5元就直接输出就行了,因为不能买东西。

        思路有了,接下去是实现,n是1000,m是1000,价格不会超过50,如果枚举的话,复杂度是n*n*m,明显会超时。由于每件商品价格不会超过50,那么只要统计下对应价格的商品件数就行了,然后用二进制优化。

       帖代码:

     

#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0xFFFFFFF
int price[55]; //统计对应价格的商品件数
int dp[1001],m;

void zeroOnePack(int volume)
{
	for (int k=m-5; k>=volume; k--)
	{
		dp[k] = max(dp[k], dp[k-volume]+volume);
	}
}
int main()
{
	int  n, p;
	while (cin >> n && n )
	{
		memset(price, 0, sizeof(price));
		for (int i=0; i<n; i++)
		{
			cin >> p;
			price[p] ++ ;
		}
		cin >> m;
		if (m <5) { cout << m << endl; continue; }

		int ans = INF;
		for (int i=1; i<=50; i++)
		{
			if (!price[i]) continue;
			price[i] --;
			memset(dp, 0, sizeof(dp));
			for (int j=1; j<=50; j++)
			{
				if (!price[j]) continue;

				int total = price[j];
				for (int gs=1 ; total>=gs; gs<=1, total-= gs)
				{
					zeroOnePack(gs*j);
				}
				zeroOnePack(total*j);
			}
			int tmp = m-dp[m-5]-i;
			if (ans > tmp) ans = tmp;
			price[i] ++;
		}

		cout << ans << endl;
	}
}


 


 

hdu 2546 饭卡 dp 饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 25502 Accepted Submission(s): 8912 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判 阅读详情

相关推荐

dp动态规划动归经典问题买书问题01背包

买书问题 dp实现 题目:买书 有一书店引进了一套书,共有3卷,每卷书定价是60元,书店为了搞促销,推出一个活动,活动如下: 如果单独购买其中一卷,那么可以打9.5折。 如果同时购买两卷不同的,那么可以打9折。 如果同时购买三卷不同的,那么可以打8.5折。 如果小明希望购买第1卷x本,第2卷y本,第3卷z本,那么至少需要多少钱呢?(x、y、z为三个已知整数)。 1、过程为一次一次的购买,每一次购买也许只买一本(这有三种方案),或者买两本(这也有三种方案), 或者三本一起买(这有一种方案),最后直到买完所有需要的书。 2、最后一步我必然会在7种购买方案中选择一种,因此我要在7种购买方案中选择一个最佳情况。 3、子问题是,我选择了某个方案后,如何使得购买剩余的书能用最少的钱?并且这个选择不会使得剩余的书为负数 。母问题和子问题都是给定三卷书的购买量,求最少需要用的钱,所以有"子问题重叠",问题中三个购买量设置为参数, 分别为i、j、k。 4、的确符合。 5、边界是一次购买就可以买完所有的书,处理方式请读者自己考虑。 6、每次选择最多有7种方案,并且不会同时实施其中多种,因此方案的选择互不影响,所以有"子问题独立"。 7、我可以用minMoney[i][j][k]来保存购买第1卷i本,第2卷j本,第3卷k本时所需的最少金钱。 8、共有x * y * z个问题,每个问题面对7种选择,时间为:O( x * y * z * 7) = O( x * y* z )。 9、用函数MinMoney(i,j,k)来表示购买第1卷i本,第2卷j本,第3卷k本时所需的最少金钱,那么有: MinMoney(i,j,k)=min(s1,s2,s3,s4,s5,s6,s7),其中s1,s2,s3,s4,s5,s6,s7分别为对应的7种方案使用的最少金钱: s1 = 60 * 0.95 + MinMoney(i-1,j,k) s2 = 60 * 0.95 + MinMoney(i,j-1,k) s3 = 60 * 0.95 + MinMoney(i,j,k-1) s4 = (60 + 60) * 0.9 + MinMoney(i-1,j-1,k) s5 = (60 + 60) * 0.9 + MinMoney(i-1,j,k-1) s6 = (60 + 60) * 0.9 + MinMoney(i-1,j,k-1) s7 = (60 + 60 + 60) * 0.85 + MinMoney(i-1,j-1,k-1)

HDU - 2546

A - 饭卡 ​ HDU - 2546 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最...

lemail0406的博客 365

【图数据库与知识图谱入门】2.2 图数据库 vs. 关系型数据库 vs. NoSQL数据库

本文对比了关系型数据库、NoSQL数据库和图数据库的核心差异与应用场景。关系型数据库以二维表结构为核心,适合结构化数据的事务处理(如MySQL),但多表关联查询性能随层级增加而下降。NoSQL数据库(如MongoDB)具有灵活schema,适合海量非结构化数据存储,但关联查询能力较弱。图数据库专注于节点-边关系建模,擅长处理复杂关联分析(如社交网络)。通过学生-课程案例展示了MySQL的多表JOIN操作和MongoDB的两种关联实现方式(内嵌文档和文档引用),揭示了不同数据库在数据关联处理上的本质区别。

kngines 1558

HDU 2546 饭卡(01背包)

电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 传送门 思路:当卡上金额大于5元的时候,我们取出最贵的商品,向金额大小为m-5的篮子里面扔东西就好了,让篮子装的东西最多,是不是花掉的钱就越多了,卡余额就最小了。用卡的总金

yuosuph的博客 242

从手机到单片机:聊聊ARM Cortex家族那些事,A、R、M系列到底有啥不同?

本文深入解析ARM Cortex家族的A、R、M三大系列处理器,揭示它们在性能、实时响应和能效方面的核心差异。从智能手机到汽车电子和物联网设备,Cortex-A、R、M各司其职,分别应对复杂运算、实时控制和超低功耗场景。通过技术指标对比和典型应用案例,帮助开发者理解如何根据DMIPS/MHz等关键参数选择适合的处理器架构。

weixin_31574149的博客 354

AURIX TC397开发板到手第一步:用iLLD库驱动LED流水灯(附完整代码)

本文详细介绍了如何使用英飞凌AURIX TC397开发板和iLLD库实现LED流水灯效果。从开发环境配置到硬件连接,再到完整的代码实现,逐步引导开发者完成项目。文章还提供了优化建议和常见问题解决方案,帮助嵌入式开发新手快速上手。

weixin_30911451的博客 398

hdu2546 — 饭卡 (01背包)

题目大意:食堂有n种菜,饭卡余额为m,当要购买一种商品前,若当前饭卡余额小于5,则购买不成功,反之则购买成功,即使购买后饭卡余额为负值,给出每种菜的价格和卡上余额,求最少可使卡上余额为多少 思路分析:这一题中,需要注意的是花费即物品本身价值,还有一个 m f [ j ] = max ( f [ j ] , f [ j - cost [ i ] ] + cost [ i ] )

不许动我的松子的博客 349

PCL 区域生长分割【2026最新版】

区域生长算法原理介绍、代码实现以及一个具体实验场景的应用案例进一步实现将分割结果的分类保存至本地文件夹。最近一次更新时间为:2026年5月4日。

点云侠的博客 40万+

hdu2546饭卡(背包)

饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 23509    Accepted Submission(s): 8267 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即

ACMan 793

VMware16虚拟机:安装Windows10系统---超详细教程

VMware16虚拟机:安装Windows10系统---超详细教程

MQ0522的博客 3万+

BMS控制板硬件设计核心要点与工程避坑指南

电池管理系统(BMS)硬件设计是保障锂电安全与寿命的关键环节,其本质是模拟前端精度、数字控制可靠性、电源完整性及电磁兼容性四大要素的系统协同。理解AFE芯片(如BQ76920)的物理层约束、MCU与专用监控IC的异构分工逻辑,是构建高鲁棒BMS的基础;而晶振布局、I²C总线匹配、MOSFET体二极管方向、开尔文采样等细节,直接决定量产良率与EMC合规性。在电动工具、储能系统、两轮电动车等中低功耗BMS应用中,成本敏感型方案常采用STM32F0+AFE架构,此时电源滤波电容选型、复位电路ESR控制、TVS/齐

weixin_30591519的博客 269

hdu 2546 饭卡(01背包)

题意: 思想一: 首先价钱最大的肯定是最后买的(当然钱数要大于5), 于是: 1)当m 2 )m>=5时先把最贵的提出来,把钱数-5转换为01背包,详细见代码。 #include #include #include #include using namespace std; int c[2005]; int dp[2500]; int cmp(int

java编程 698

ICC2:mem出pin的Off Grid问题

这个命令本意是解决跨制成调用IP时在IP出pin位置加一定的routing blockage,限制绕线在一定范围内只能走直线出pin,用来解决off-grid问题也有很好的效果。在ICC2做先进工艺时会有off-grid的问题,off-grid可以理解为绕线没有在preferred方向track上。测试发现,2022版本以前的ICC2绕线容易有off-grid问题。主要在mem出pin的M2/M3层次上,切换版本绕线能很大程度上解决这个问题。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1640

HDU 2546 饭卡 题解(动态规划)

链接http://acm.hdu.edu.cn/showproblem.php?pid=2546

madaidao的专栏 2936

msf后渗透之获取登入password、远程控制、调用摄像头

在terminal输入load kili creds_all直接获取密码(不一定成功) 使用kiwi_cmd sekurlsa::logonpasswords获取密码

m0_61506558的博客 2966

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

【HDU 2546】饭卡(动态规划)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 Problem Description: 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种...

innocence的博客 719

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

HDU 2546 饭卡 (动态规划01背包)

http://acm.hdu.edu.cn/showproblem.php?pid=2546 先用5元钱买最贵的东西,然后用剩下的钱买价值最大的东西,也就是01背包问题。 先进行排序,找出最大的,然后对剩下的商品进行动态规划,而顺序不影响。 参考博客:http://blog.csdn.net/juststeps/article/details/8714303 #include #

Benjamin_Z的博客 1364

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HDU 2546 饭卡 动态规划01背包

http://acm.hdu.edu.cn/showproblem.php?pid=2546 题意:   给你一些饭菜的价格,和你饭卡的余额,余额大于等于5元时可以刷任何价格的菜,算出你买了这些菜之后饭卡中最少的一组解(余额可以为负)。 坑爹:   这道题中,他的价格也就是背包中的容量,也是背包中的价值,总余额如果超出5元要将总余额减去5元的钱尽量用掉。   解法   用到了一...

weixin_30872157的博客 100

HDU 2546—饭卡 动态规划入门

Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。   In

lois_123的专栏 683

[HDU- 2546] 饭卡(动态规划&&背包)

Link:http://acm.hdu.edu.cn/showproblem.php?pid=2546Problem Description电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜

Hello Joanna 504

动态规划专题 01背包问题详解 HDU 2546 饭卡

http://www.cnblogs.com/fancy-itlife/p/4394398.html 动态规划专题 01背包问题详解 HDU 2546 饭卡 我以此题为例,详细分析01背包问题,希望该题能够为大家对01背包问题的理解有所帮助,对这篇博文有什么问题可以向我提问,一同进步^_^ 饭卡 Time Limit: 5000/1000

糖分 481

hdu_2546_饭卡(01背包)

题目连接:hdu_2546_饭卡 题意:中文,不解释 题解:先拿5元来买最贵的,最后就是一个01背包,这里也算用到贪心的思想 #include #define F(i,a,b) for(int i=a;i<=b;i++) using namespace std; inline void up(int &x,int y){if(x<y)x=y;} int n,a[1001],dp[1200

bin_gege的博客 319

hdu 2546 饭卡-动态规划01背包

电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 Input 多组数据。对于每组数剧:第一行为正整数n

GYH0730的博客 303

B - 饭卡 HDU - 最值型01背包

B - 饭卡  HDU - 2546  预处理一下最大价值的用5元去买。特判初始状态钱小于5的情况   #include&lt;bits/stdc++.h&gt; using namespace std; #define maxn 1552 int n,m,a[maxn]; int dp[maxn],ans; int main() { while(cin&gt;&gt...

BePosit的博客 382

hdu2546题解

hdu2546题解题意中文题惯例不翻译 uestc本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。笺释这算是排序dp问题

SoniciSika 333
上一篇: Standford机器学习 神经网络的学习(Neural Network Learning)
下一篇: Standford 机器学习应用的建议及机器学习系统的设计
Jackie_Zhu
博客等级 码龄18年 343粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址