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个,两人轮流劃掉,每次只 可劃去其中一堆中的任 意数, 不可以都不劃,劃到最後一个的算输 立即下载

相关推荐

关于卷积过程中通道数如何变化问题

对卷积操作前后通道数问题进行解释,输出通道数=卷积核的个数。

你好,明天,,的博客 4316

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

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

gitblog_00040的博客 711

BugkuCTF-PWN题pwn2-overflow超详细讲解

解题思路 1)计算出get_shell_的地址偏移量 2)算出来之后就直接溢出到后门函数 知识点 x64函数调用规则 解题之前我们先学下linux x64的函数调用规则。 x64机器在调用某个函数前,比如int func(int a, int b, int c, int d, int e, int f, int g, int h),首先他会把前6个参数从左往右存入到寄存器rdi、rsi、rdx、rcx、r8、r9,其余参数存入到栈里,保存的顺序是从右往左入栈。比如abcdef会存入到寄存器里,然后一次入栈h

am_03的博客 3013

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

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

weixin_39594191的博客 1501

STM32实战篇:使用USART发送/接收数据

在发送字符时也可以直接使用其对应的ASCLL码,例如: USART_SendData(USART1, 0x61);

qq_74114817的博客 596

【LLM技术全景】规模定律与模型演进:为什么模型越大越强?

规模定律性能 ∝ 参数量^N性能 ∝ 数据量^M性能 ∝ 计算量^L其中 N, M, L 是小于1的正数(通常0.05~0.15)关键观察损失与规模的关系呈幂律(不是线性,也不是对数)三个要素(参数、数据、计算)需要协调增长只增加其中一个要素,收益会边际递减规模定律(Scaling Law):1. 模型性能与参数量、数据量、计算量呈幂律关系2. Kaplan定律(2020):参数量是主要因素3. Chinchilla定律(2022):数据和参数同等重要,最优比例1:20。

专注:太空算力、AI infra、异构调度、大模型成本工程 496

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

全志V3S嵌入式驱动开发(uboot移植)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】 安装了ubuntu操作系统,有了开发板,下面就可以进行我们的开发工作了。第一步,我们要面临的问题就是uboot移植。一般来说,嵌入式的基础环境就是uboot、linux和rootfs。uboot完成一些基本硬件的初始化,比如cpu频率设置、ddr初始化、加载linux等等。早前,uboot的烧入比较麻烦,需要jtag工具才能完成。现在来说,很多soc支持系统直接从sd卡启动,这对开发

嵌入式-老费,一个分享专业嵌入式知识的blog 2821

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

Classic AUTOSAR精讲专栏目录

欢迎大家来到钢琴上的汽车软件创建的《Classic AUTOSAR精讲系列专栏》,期待在这里能够与大家一起进步,分享成功,分享喜悦!下面蓝色的文章标题都是传送门,点击直接跳转到对应文章。

酒无忧的博客 3911

51单片机 驱动有源/无源蜂鸣器+Proteus仿真

51单片机 驱动有源/无源蜂鸣器+Proteus仿真 相关篇《51单片机 Proteus仿真有源蜂鸣器始终不响原因及解决方法》 电路搭建 采用NPN管驱动有源蜂鸣器电路 采用PNP管驱动有源蜂鸣器电路 采用PNP管驱动无源蜂鸣器 采用NPN管驱动无源蜂鸣器 Proteus元器件列表 实例代码 /************************************************************************************* * 实验现象:下载程序

perseverance51博客 2万+

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

清华源pip install出现ERROR: Could not find a version that satisfies the requirement的解决方案

本文主要介绍了清华源pip install出现ERROR: Could not find a version that satisfies the requirement的解决方案,希望能对学习python的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 8万+

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

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

小G的ACM之路 787

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

余额充值