POJ - 1276 Cash Machine 多重背包模板题

Linux下安装cx_Oracle,连接oracle数据库 通过python连接oracle数据库,在Linux服务器运行时,缺少cx_Oracle模块,则需要在linux下安装对应的依赖,需要用到的依赖如下:①oracle客户端②cx_Oralce。 阅读详情

Cash Machine
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 34097 Accepted: 12357

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

Hint

The first data set designates a transaction where the amount of cash requested is @735. The machine contains 3 bill denominations: 4 bills of @125, 6 bills of @5, and 3 bills of @350. The machine can deliver the exact amount of requested cash. 

In the second case the bill supply of the machine does not fit the exact amount of cash requested. The maximum cash that can be delivered is @630. Notice that there can be several possibilities to combine the bills in the machine for matching the delivered cash. 

In the third case the machine is empty and no cash is delivered. In the fourth case the amount of cash requested is @0 and, therefore, the machine delivers no cash.

Source


二进制优化的多重背包

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
int main()
{
	int t,V,v,n,dp[100005],i,j,m;
	while(~scanf("%d",&V))
	{
		memset(dp,0,sizeof(dp));
		scanf("%d",&t);
		while(t--)
		{
			scanf("%d %d",&n,&v);
			for(i=1;(i<<1)<n;i<<=1)
			{
				for(j=V;j>=i*v;j--)
				{
					dp[j]=max(dp[j],dp[j-i*v]+i*v);
				}
			}
			m=n-i+1;
			for(j=V;j>=m*v;j--)
			{
					dp[j]=max(dp[j],dp[j-m*v]+m*v);
			}	
		}
		printf("%d\n",dp[V]);
	} 
	return 0;
 }

单调队列优化的多重背包

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
struct node{
	int num,value;
}que[500000]; 
int head,tail,dp[100005];
void push(int x,int y){
	while(tail>head&&que[tail-1].value<y)
	tail--;
	que[tail].num=x;
	que[tail++].value=y;
	return ;
}
int main()
{
	int i,j,V,n,c,w;
	while(~scanf("%d %d",&V,&n))
	{
		memset(dp,0,sizeof(dp));
		while(n--)
		{
			scanf("%d %d",&c,&w);
			c=min(c,V/w);
			for(i=0;i<w;i++)
			{
				head=0;
				tail=0;
				for(j=0;j<=(V-i)/w;j++)
				{
					push(j,dp[j*w+i]-j*w);
					while(tail>head&&que[head].num<j-c)
					head++;
					dp[j*w+i]=que[head].value+j*w;
				}
			}
		}
		printf("%d\n",dp[V]);
	}
	return 0;
 }


python-oracledb——利用python连接Oracle数据库的利器 python-oracledb驱动程序是一个Python扩展模块,可以访问Oracle数据库。它具有支持Python数据库API v2.0规范的全面功能,具有相当多的附加内容和一些排除项。 python-oracledb驱动程序是cx_Oracle 8.3的重命名的主要版本继承者。... 阅读详情

相关推荐

使用cx_Oracle模块将Oracle数据库中的数据导出到CSV文件

在Python中,我们可以使用cx_Oracle模块来连接Oracle数据库,并将数据库中的数据导出到CSV文件。这就是使用cx_Oracle模块将Oracle数据库中的数据导出到CSV文件的方法。其中,username是数据库的用户名,password是密码,connection_string是连接字符串,用于指定数据库的位置和其他连接参数。下面是一个详细的步骤,演示如何使用cx_Oracle模块将Oracle数据库中的数据导出到CSV文件。首先,我们需要安装cx_Oracle模块。

HackQuestR的博客 487

【python】cx_Oracle库学习

python连接数据库,cx_Oracle库学习。

MAOZI8的博客 2430

Computers & Security 投稿实战:从零到一详解避坑指南

本文详细解析了向《Computers & Security》投稿的全流程避坑指南,包括ORCID账号注册、文件格式统一、Editorial Manager®系统操作技巧等关键步骤。特别强调了cover letter撰写、Declaration of Interest Statement准备以及PDF生成后的检查要点,帮助研究者高效完成投稿流程。

weixin_29228203的博客 686

cx_Oracle和oracledb的爱恨情仇

实习生:我要用python访问oracle,我究竟该用哪个库啊,网上搜的有两个,一个是cx_Oracle另一个是oracledb,这两个有什么区别?我:话说那是2022年5月一个阴云密布的日子,甲骨文发布了python oracledb驱动程序。与早期的cx_Oracle驱动程序(创建于1999年)一样,该模块允许Python应用程序连接到Oracle数据库,执行SQL和PL/SQL语句,并执行SODA操作。这两个驱动程序都实现了Python数据库API规范2.0版,有很多扩展,只有一些必要的遗漏。

SunnyRivers 2601

SDI-12协议与STM32 进行uart通信

其中DIR_OUT_SDI是一个IO引脚,控制UART_TX_SDI是否使能,U10是三态门IC,即拉低DIR_OUT_SDI使能stm32输出,拉高DIR_OUT_SDI失能输出,串口配置8位数据位,偶校验,1位停止位,1200波特率。示波器测试得到传感器的应答信号如下:第一个是唤醒信号,拉高电平13毫秒,之后保持20毫秒低电平,第二个数据帧是激活信号,即ascii码: "0!",第三个是传感器的应答信号:"0\r\n"

weixin_42186805的博客 4419

GNSS数据资源全解析:从DCB到BSX文件的下载与应用指南

本文系统解析了GNSS数据处理所需的核心数据资源,包括DCB、BSX、SP3、CLK等关键文件的官方下载路径与应用方法。详细介绍了CDDIS、武汉大学镜像站等权威数据源,并提供了从数据下载到实际应用的完整指南,帮助用户高效获取GNSS数据,提升精密定位处理效率。

weixin_29246195的博客 146

poj1276Cash Machine【多重背包模板题】

SubmitStatus 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 disti

MissZhou要努力 2547

ks-快手滑块验证码-Js逆向

本文分析了快手滑块验证码的破解过程。首先通过抓包找到验证码背景图接口,发现需要动态获取captchaSession参数。然后深入分析验证流程,发现verifyParam参数被加密处理,需要追踪其生成逻辑。文章详细解析了加密参数c的构成,包括captchaSn、滑动距离、轨迹信息等,并指出轨迹验证较为严格。最后通过对比浏览器和本地生成的加密值,确认加密逻辑正确,但指出轨迹生成仍需优化。作者建议参考相关文章深入分析轨迹逻辑,并提供了验证成功的截图作为参考。

2302_76420666的博客 1884

POJ 1276 Cash Machine(动态规划、多重背包)

这道题是典型的多重背包题,就是说给你的物品有一个去的件数的上限,我们常用的解决多重背包问题的方法是:将件数乘以费用超过背包容量的物品可以使用完全背包的方法进行求解;除此之外的物品我们采用二进制的思想,将该物品的件数拆分成二进制上的数后,看成一个物品进行01背包。这样通过这两种方法

Bright 1154

Orin 调试GMSL camera 96712手册重点

96712基础理解

乐于分享 9235

Linux ARM平台开发系列讲解(摄像头V4L2子系统) 2.12.5 V4L2 control的原理和实现

既然涉及到视频输入,就会有很多与 相关的效果,比如对比度、饱和度、色温、白平衡等等,这些都是通用的、必须的控制项,并且大多数仅需要设置一个整数值即可。 内核中已经为我们提供了这个控制类型的,我们只需要明确自己需要添加什么控制类型,然后将其添加进内核中即可。该部分摄像头代码一半厂家会提供驱动或者相对应的参数,否则没有图像处理知识很难开发出来。 返回总目录...

DSMGUOGUO的博客 1439

poj1276 Cash Machine(多重背包)

Cash Machine 本题大意:给出一个最大金额,然后给出k中币的金额和数量,求能正好提供的最大小于等于最大金额的金额。 本题是多重背包模板题,直接套上模版就可以解决。 #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include &lt...

zxc757126309的博客 188

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ1267 Cash machine 多重背包

传送门:POJ1276 题意:给定一种新货币的多种面额和每种面额的数量和一个数额上限,问在不超过数额上限的前提下用给定的货币最多能凑出多大数额来。 思路:典型的多重背包,可以说是模板题,只不过本题中w[i]==v[i]而已。 可以用二进制优化,也可以单调队列优化。 不明白多重背包是啥的请自行搜索《背包九讲》。 二进制优化代码: #include #include #include #i

WA是一笔财富 319

深度学习工具包 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")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

【POJ 1276】Cash Machine

【POJ 1276】Cash Machine多重背包模板题 这里分享个背包的好文章:http://blog.csdn.net/lyhvoyage/article/details/8545852 或者直接去看背包九讲 看了背包九讲 背包从此不用讲…… 麻麻再也不用担心。。。就是个模板 不过我写的极度精简……输入跟处理都放一块了。。。耗时不少= =建议拆开写 时间用的应该能少点。。。代码如下:#in

ACMer' 1070

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Cash Machine POJ - 1276 多重背包

一、内容 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 ...

Tizzi的博客 845

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 denomin

深海沧澜的博客 332

[多重背包] POJ1276 Cash Machine (二进制优化)

题目 有各种不同面值的货币,每种面值的货币有不同的数量,请找出利用这些货币可以凑成的最接近且小于等于给定的数字cash的金额。 思路 多重背包模板题。 1.朴素的多重背包,每个状态转移时枚举用的某种货币的个数,复杂度:O(C∗∑n[i])O(C∗∑n[i])O(C*\sum n[i]),TLE。 2.二进制优化,背包九讲里面有。 此处应该注意的是,1…n的任意整数用尽量少的几个整数表示...

OI - IceCab 474

Cash Machine POJ - 1276 (多重背包)

链接:http://poj.org/problem?id=1276 题意:给出一个n 代表最多拿的值为n, m种钱币, 每种有 x个, 值为y,问在不超过n的情况下最多能拿多少钱。解题思路:也算是多重背包的模板题了,做法是将多重背包化成0 1背包, 将每种钱币分别分成 1个 2个 4个…..当不够分的时候就将剩下的也当作一组, 这样每一组都对应一个不同的值 y*1, y*2, y*4….然后直接0

sdut16szq的博客 414

poj 1276 Cash Machine(多重背包+倍增)

Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17441   Accepted: 6038 Description

志当存高远 1340

第一周下多重背包(Cash Machine POJ - 1276 )

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 sup

JSASL的博客 214

POJ1276: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 denominatio

ACM!荣耀之路! 1724

POJ 1276 Cash Machine (多重背包&单调队列)

http://poj.org/problem?id=1276 模板题。 完整代码: /*110ms,4316KB*/ #include #include const int mx = 1005; const int mxw = 1000005; int w[mx], m[mx], dp[mxw], deq[mxw], deqv[mxw]; int solve(int m

AC,∑ndless 1846

POJ1276:Cash Machine(多重背包)

题目:http://poj.org/problem?id=1276 多重背包模板题,没什么好说的,但是必须利用二进制的思想来求,否则会超时,二进制的思想在之前的博客了有介绍,在这里就不多说了。 #include &lt;iostream&gt; #include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;algori...

weixin_33895475的博客 108

poj1276 Cash Machine-多重背包

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 sup

ly59782的博客 370
上一篇: POJ - 1836 Alignment
下一篇: 背包模板(01,完全,多重背包的二进制优化和单调队列优化
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值