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的博客 492

【python】cx_Oracle库学习

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

MAOZI8的博客 2433

C#海康威视摄像头控制,将IntPtr转换成Bitmap图片

C#通过skd控制海康威视摄像头,获取bitmap格式图片

ReflexMechanism的博客 6595

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 2606

SAP 关于WPS上传文件提示“文档中不包含数据“ 和“程序正在运行中“处理办法

最近这一周经常有用户反馈,使用WPS上传文件系统报错,一直提示“程序正在运行中”,另外在导入数据的时候提示"文档中不包含数据",跟进运维过程中遇到的这两种情况,分享一下处理的办法,如果各位更好的办法也可以给我留言分享。

我小时候很黑的博客 2898

(P2)PALM软件的基本使用流程

上一篇介绍了PALM在Ubuntu系统上的下载安装及安装后的目录文件结构,这一篇以自带的案例介绍软件的基本操作流程。(请转至example_cbl项目) 输入 声明:官网均有各个变量的说明,以下代码来自软件自带案例 palm的最小输入文件是p3d文件,以下是example_cbl_p3d的详细说明。(文件语言格式Fortran,请自行先学习下语言的基本语法。笔者也是新学者,有非常多的问题,很多参数也不能准确的说出是什么意思,还请不吝赐教,谢谢!!!) !几点说明 !1、该运行文件基本由三大块组成:1)in

ysqzhatian的博客 3272

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

从solidworks导出URDF模型

一、下载sw_urdf_exporter插件 ROS目前提供了SolidWorks转URDF的插件,叫做sw_urdf_exporter,从http://wiki.ros.org/sw_urdf_exporter下载sw2urdfSetup.exe文件,下载后点击安装,安装完成后就能在solidworks中导出URDF模型了。 二、创建solidworks模型 下面以较为简单的四轮小车为例进行说...

weixin_45168199的博客 4万+

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

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

Bright 1154

开启虚拟人物互动新时代:探索相芯Avatar SDK驱动功能(Android)

相芯SDK提供了男孩和女孩Avatar驱动模型,这些模型具备半身驱动和全身驱动的功能,使得虚拟角色能够根据用户的面部表情和动作实时模仿和响应。半身驱动功能: 相芯SDK的男孩和女孩Avatar驱动模型具备上身驱动功能,即能够通过用户的面部表情和动作来驱动虚拟角色的上半身行为。这意味着用户的面部表情、头部转动和上半身姿态等动作可以直接映射到虚拟角色上,使得虚拟角色能够栩栩如生地模仿用户的动作。例如,用户微笑时,虚拟角色会展现出笑容;用户转动头部时,虚拟角色也会相应地转动头部。

Faceunity2023的博客 638

Java网页访问报错?手把手教你解决JRE插件缺失和浏览器拦截问题(附详细截图)

本文针对Java网页访问时常见的JRE插件缺失和浏览器拦截问题,提供了详细的诊断与解决方案。文章首先解释了问题根源在于现代浏览器出于安全考虑停止了对Java插件的支持,然后手把手指导用户确认Java安装、在控制面板配置安全站点列表,并针对Chrome、Edge、Firefox等主流浏览器的不同拦截机制给出了具体的应对策略,最后提供了系统性的故障排查清单,帮助用户彻底解决访问障碍。

weixin_29233857的博客 236

poj1276 Cash Machine(多重背包)

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

zxc757126309的博客 188

pycharm报错cannot start the IED:Error occurred during initialization of VMagent library failed...如何解决?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1954

POJ1267 Cash machine 多重背包

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

WA是一笔财富 319

基于Simulink的加速度计振动分析:单自由度质量-弹簧-阻尼系统

摘要:基于Simulink的加速度计单自由度振动分析 本文研究了加速度计的单自由度(SDOF)质量-弹簧-阻尼系统模型,通过MATLAB/Simulink平台建立了完整的振动分析仿真系统。文章详细阐述了理论建模过程,推导了系统运动微分方程和传递函数,并提供了Simulink模型搭建的具体步骤和MATLAB实现代码。研究通过正弦扫频、随机振动和冲击响应三种典型输入信号,分析了系统的幅频特性、相频特性及时域响应,验证了加速度计的工作机理。仿真结果表明,该方法能有效模拟加速度计在不同激励条件下的动态特性,为传感器

AI的内部世界的博客 176

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

【POJ 1276】Cash Machine

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

ACMer' 1070

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

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

深海沧澜的博客 333

[多重背包] 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的博客 415

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、付费专栏及课程。

余额充值
⌂ 换网址