UVa 357 Let Me Count The Ways (完全背包)

Ndless:适用于本机应用程序的TI-Nspire计算器扩展 适用于TI-Nspire OS <= v5.3.0.564的Ndless r2018 在计算器上安装Ndless可以运行汇编程序。 Ndless结合了可执行的加载器和实用程序,可将TI-Nspire开放给第三方C和程序集开发。 官方网站位于: -> 可以在以下位置找到源代码: -> 可以在线获取用户指南,请务必阅读以获取更多安装说明: -> 可以在以下位置找到开发人员指南: -> 拉请求和问题,欢迎! 有关更深入的信息,请访问Wiki: -> 快速指南 操作系统5.2.0.771 + 5.3.0.564 先决条件:CX II,CX II-T或CX II CAS上的OS 5.2.0.771或5.3.0.564 将ndless_installer_5.2.0-5.3.0.tns转移到名为“ ndless”的文件夹中(顶层) 将ndless_resour 立即下载

357 - Let Me Count The Ways

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=293

After making a purchase at a large department store, Mel's change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a convenience store. Again his change was 17 cents. This time he received 2 nickels and 7 pennies. He began to wonder ' "How many stores can I shop in and receive 17 cents change in a different configuration of coins? After a suitable mental struggle, he decided the answer was 6. He then challenged you to consider the general problem.

Write a program which will determine the number of different combinations of US coins (penny: 1c, nickel: 5c, dime: 10c, quarter: 25c, half-dollar: 50c) which may be used to produce a given amount of money.

Input

The input will consist of a set of numbers between 0 and 30000 inclusive, one per line in the input file.

Output

The output will consist of the appropriate statement from the selection below on a single line in the output file for each input value. The numberm is the number your program computes, n is the input value.

There are m ways to produce n cents change.

There is only 1 way to produce n cents change.

Sample input

17 
11
4

Sample output

There are 6 ways to produce 17 cents change. 
There are 4 ways to produce 11 cents change. 
There is only 1 way to produce 4 cents change.

思路:dp[i] += dp[i - coin[k]];

注意会超int。


完整代码:

/*0.019s*/

#include<cstdio>
#include<cstring>
const int coin[5] = {1, 5, 10, 25, 50};
const int maxn = 30001;

long long dp[maxn];

int main()
{
	int i, k, n;
	dp[0] = 1;
	for (k = 0; k < 5; ++k)
		for (i = coin[k]; i < maxn; ++i)
			dp[i] += dp[i - coin[k]];
	while (~scanf("%d", &n))
	{
		if (n < 5) printf("There is only 1 way to produce %d cents change.\n", n);
		else printf("There are %lld ways to produce %d cents change.\n", dp[n], n);
	}
	return 0;
}

357游戏解法与扩展 有三堆圆圈圈各為3.5.7个,两人轮流劃掉,每次只 可劃去其中一堆中的任 意数, 不可以都不劃,劃到最後一个的算输 立即下载

相关推荐

ANSYS接触分析实战:从法兰连接案例看接触刚度与穿透容差的黄金搭配

本文以法兰连接为实战案例,深入解析了ANSYS接触分析中接触刚度(FKN)与穿透容差(FTOLN)的参数设置策略。通过系统性敏感性分析,揭示了这对关键参数的博弈关系与调优逻辑,旨在帮助工程师在保证计算收敛的同时,获得高精度的有限元分析结果,有效解决工程中的非线性接触难题。

moon9的博客 314

探索 Ndless:Nspire计算器的开源编程平台

探索 Ndless:Nspire计算器的开源编程平台 去发现同类优质开源项目:https://gitcode.com/ Ndless 是一个革命性的开源项目,它为 Casio Nspire 系列图形计算器提供了 programming 能力,让这款强大的数学工具焕发新的活力。通过 ,用户可以编写和运行 Lua、C 和 Rust 代码,极大地拓展了 Nspire 的功能边界。 项目简介 Ndless...

gitblog_00040的博客 711

电路方案分析(十二)USB Type-C PD 移动电源参考设计方案

TPD8S300为USB Type-C连接器的CC1,CC2,SBU1和SBU2引脚集成了四个通道的20v短到vbus和过压保护。TPD8S300集成了八个IEC61000-4-2ESD保护通道,用于USB Type-C连接器的CC1、CC2、SBU1、SBU2、DP_T (顶侧D-) 、DM_T (顶侧D-) 、DP_B (底侧D-) 引脚。当电源组是接收器并为其自身的电池充电时,该芯片会对电池充电,而在电源模式期间,该芯片充当DC-DC转换器以生成VBUS。

小幽余生不加糖 2万+

norestart 未成功安装_如何安装道路之星?

1.打开Ti的连接软件2.根据计算器的OS版本,把相应版本目录下的ndless文件夹拖到计算器的根目录下,并关闭计算器的提示框为的计算器把ndless_大黑文件或ndless_小白文件这个文件拖到计算器的根目录,在计算器出现提示框后,按Enter键安装。电脑上的进度提示条可以直接取消。OS为的计算器转至手持设备端,打开然后按下menu按键。稍等片刻,Ndless 即安装成功!但请注意,安装Endl...

weixin_39594191的博客 1501

AArch64 ARM64 寄存器介绍

除了上述通用寄存器,还有FPSR(浮点状态寄存器)和 FPCR(浮点控制寄存器)等。X29寄存器和X30寄存器在函数调用和堆栈帧的管理中扮演着关键角色。AArch64架构提供了31个通用寄存器,每个寄存器都可以用作64位X寄存器(X0~X30)或32位W寄存器(W0~W30)。使用X寄存器将导致64位的计算,使用W寄存器将导致32位的计算。EL0、EL1、EL2和EL3是AArch64架构中定义的四个特权级别(Exception Levels),用于支持不同的执行环境和特权级别。

lml435035844的博客 1万+

人像抠图 + OpenGL ES 还能这样玩?没想到吧(附带源码)

OpenGL ES 利用抠图算法实现人像留色。

字节流动 3万+

SCAU专题训练II - DP---C-- Dividing coins

题目描述 It’s commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce...

Leo_zehualuo的博客 373

SAP GR(Group Reporting)配置篇(五)

1.5、合并的货币换算1.5.1指定折算比率菜单路径组报表的SAP S4HANA >合并的货币换算>-指定折算汇率事务代码GCRF说 明1.5.2维护汇率菜单路径组报表的SAP S4HANA >合并的货币换算>维护汇率事务代码CXCC/OB08说 明实际测试的时候根据实际情况维护汇率。输入换算比率。1.5.3定义汇率标识符菜单路径组报表的SAP S4HANA >合并的货币换算>定义汇率标识符事务代码OC41说 明配置了月末汇率和平均汇率。

weixin_43853754的博客 554

UVA-357-Let Me Count The Ways

同样求指定数的钱的划分方法~ 输出的时候需要注意,如果答案为1的话需要特殊输出 代码: #include #include #include using namespace std; const int maxn=30010; int n,num[5]={1,5,10,25,50}; long long f[maxn]; void Init() { f[0]=1; for

z309241990的专栏 1160

SIWAVE+ADS提取PCB走线寄生参数

本文将介绍一种很适合PCB走线提取寄生电感等参数的方法,即是通过SIWAVE将PCB走线的S参数提取出来,再通过ADS将S参数转换成电感、电容值。

sinat_15150363的博客 1765

一文吃透!C#上位机CAN总线通信开发:从协议解析到数据可视化

CAN底层协议仅定义了8字节数据的传输规则,实际业务需自定义应用层协议,实现多类型数据的有序传输,这是数据解析的核心。仲裁ID(16进制)数据长度(DLC)数据场格式业务含义解析规则0x0014字节0~3:温度数据温度采集(单位:℃)4字节→float类型(大端/小端需统一,如西门子PLC格式)0x0022字节0~1:转速数据电机转速(单位:r/min)2字节→short类型(Int16)0x0031字节0:bit0~bit7设备状态(8路开关量)

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 847

UVA 357 Let Me Count The Ways(完全背包)

UVA 357 Let Me Count The Ways(完全背包) http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=293 题意: 有5种硬币: 1分 5分 10分 25分 和50分. 现在给你一个面值n, 问你有多少种方法能利用上述硬币组合出n分的金钱. 分析: 典型的完全背包问题. 本题的限制条件: 硬币钱数正好等于n

code 1374

C++软件调试与异常排查从入门到精通专栏介绍与文章汇总

根据近几年排查软件异常的实践与经验,系统地讲解了C++软件异常常见原因与常用排查方法,以图文并茂的方式给出具体的分析实例,带领大家逐步掌握C++软件异常排查的相关技术与要领。

dvlinker的技术专栏 23万+

UVA - 357 Let Me Count The Ways(完全背包)

题目大意:给定五种硬币 1c, 5c, 10c, 25c, 50c,及一个面值额,看有多少种方法可以组成当前面值额。 解析:比较简单的dp题 用dp[v]表示:当前价格用的方法个数 状态转移方程:dp[v + coin[i]] += dp[v]; 唯一

小G的ACM之路 787

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Camera2Demo

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

UVA 357 Let Me Count The Ways(完全背包)

题目概括: 一共有1、5、10、25、50五种面值的钱币,输入多组金额,分别求出用这五种钱币一共有多少种组合方式。 题目解析: 该题目涉及了完全背包的算法。 有两个博客对于这个算法有详细的解释,在这里引用一下: https://blog.youkuaiyun.com/qq_38984851/article/details/81133840 https://www.cnblogs.com/fengziwei/...

walalilongla! 287

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

UVA 357 Let Me Count The Ways 完全背包

又是重复问题,LRJ估计要突出这里基础的重要性 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long

Commence,的艰苦历程 437

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

UVA - 357Let Me Count The Ways(完全背包)

题目:UVA - 357Let Me Count The Ways(完全背包) 题目大意:给出N,问用1, 5, 10, 25, 50,这些硬币能够凑出N的方式有多少种。 代码: #include #include const int N = 5; const int maxn = 30005; const int coin[N] = {1, 5, 10, 25, 50

859

【解题报告】uva357_Let Me Count The Ways(让我来数数方案, dp, 完全背包)

357 - Let Me Count The Ways Time limit: 3.000 seconds  Let Me Count The Ways  After making a purchase at a large department store, Mel's change was 17 cents. He received 1

huanghuchuan 699

UVA.357 Let Me Count The Ways (DP 完全背包)

UVA.357 Let Me Count The Ways (DP 完全背包)题意分析与UVA.UVA.674 Coin Change是一模一样的题。需要注意的是,此题的数据量较大,dp数组需要使用long long 类型;另外输出方案为1个和多个的时候,语句是不同的。

Pengwill's Blog 350

UVA 357 Let Me Count The Ways (dp + 完全背包)

Let Me Count The Ways  After making a purchase at a large department store, Mel's change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a co

Remilia's 1299

UVA357 LA5251 Let Me Count The Ways【0/1背包】

After making a purchase at a large department store, Mel’s change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a convenience store. Again his change wa...

海岛Blog 681

UVa 357 - Let Me Count The Ways 背包

Let Me Count The Ways  After making a purchase at a large department store, Mel's change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a co

Azarath Metrion Zinthos 1014

uva 357 Let Me Count The Ways(01背包)

题目连接:357 - Let Me Count The Ways 题目大意:有5种硬币, 面值分别为1、5、10、25、50,现在给出金额,问可以用多少种方式组成该面值。 解题思路:和uva674是一样的, 只是上限不一样, 还有注意下输出。 #include #include const int N = 30005; const int val[5] = {

不慌不忙、不急不躁 1427

UVA 357 Let Me Count The Ways

背包变形。 #include #include #include #include #include using namespace std; typedef unsigned long long ULL; const int MAXN = 30010; const int INF = 0x3f3f3f3f; ULL f[30010]; int n, C; int V[] =

Wall_F的专栏 726

UVa 357 Let Me Count The Way

这篇文章介绍了如何使用动态规划解决美分硬币找零的组合数问题。题目给定5种硬币面额(1、5、10、25、50美分),要求计算组成指定金额的不同组合方式。作者通过动态规划预处理所有可能金额(0到30000美分),定义状态dp[i][j]表示使用前i种硬币组成金额j的组合数,并推导了状态转移方程。最终代码采用二维数组实现动态规划,预处理后直接查询输出结果。文章强调了组合数与排列数的区别,并提供了完整的C++实现代码,能够高效处理输入查询。

寂静山林 209

UVA - 357 Let Me Count The Ways

#include int main() { long long n, M[5] = {1, 5, 10, 25, 50}, DP[30005] = {0}; DP[0] = 1; for (int i = 0; i < 5; i++) { for (int j = M[i]; j < 30005 ; j++) if (DP[j-M[i]]) DP[j] += DP[j-

Bingo 1686
上一篇: UVa 10739 String to Palindrome (DP)
下一篇: UVa 147 Dollars (完全背包)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值