USACO section 2.3 Money Systems(dp)

Money Systems

The cows have not only created their own government but they have chosen to create their own money system. In their own rebellious way, they are curious about values of coinage. Traditionally, coins come in values like 1, 5, 10, 20 or 25, 50, and 100 units, sometimes with a 2 unit coin thrown in for good measure.

The cows want to know how many different ways it is possible to dispense a certain amount of money using various coin systems. For instance, using a system of {1, 2, 5, 10, ...} it is possible to create 18 units several different ways, including: 18x1, 9x2, 8x2+2x1, 3x5+2+1, and many others.

Write a program to compute how many ways to construct a given amount of money using supplied coinage. It is guaranteed that the total will fit into both a signed long long (C/C++) and Int64 (Free Pascal).

PROGRAM NAME: money

INPUT FORMAT

The number of coins in the system is V (1 <= V <= 25).

The amount money to construct is N (1 <= N <= 10,000).

 

Line 1:Two integers, V and N
Lines 2..:V integers that represent the available coins (no particular number of integers per line)

SAMPLE INPUT (file money.in)

3 10
1 2 5

OUTPUT FORMAT

A single line containing the total number of ways to construct N money units using V coins.

SAMPLE OUTPUT (file money.out)

10


题解:f[i]+=f[i-c[j]]; 当只有一种货币时只要能取的值方法数均为1,当多种货币时每增加一种,只要在原先的基础上加上能达到面额的方法数即可

        f[i] 的方法数等于不用此种货币的方法数,加上用此种货币后的方法数。

 

/*
ID:nealgav1
PROG:money
LANG:C++
*/
#include<fstream>
#include<cstring>
using namespace std;
const int mm=11000;
ifstream cin("money.in");
ofstream cout("money.out");
long long f[mm];
int cost[33];
int main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++)
  cin>>cost[i];
  memset(f,0,sizeof(f));
  f[0]=1;
  for(int i=0;i<n;i++)
  {
    for(int j=cost[i];j<=m;j++)
    f[j]+=f[j-cost[i]];
  }
  cout<<f[m]<<endl;
}


 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: money
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3420 KB]
   Test 2: TEST OK [0.000 secs, 3420 KB]
   Test 3: TEST OK [0.000 secs, 3420 KB]
   Test 4: TEST OK [0.000 secs, 3420 KB]
   Test 5: TEST OK [0.000 secs, 3420 KB]
   Test 6: TEST OK [0.000 secs, 3420 KB]
   Test 7: TEST OK [0.000 secs, 3420 KB]
   Test 8: TEST OK [0.000 secs, 3420 KB]
   Test 9: TEST OK [0.000 secs, 3420 KB]
   Test 10: TEST OK [0.000 secs, 3420 KB]
   Test 11: TEST OK [0.000 secs, 3420 KB]
   Test 12: TEST OK [0.000 secs, 3420 KB]
   Test 13: TEST OK [0.000 secs, 3420 KB]

All tests OK.

Your program ('money') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
1 1
1
------- test 2 ----
3 10
1 2 5
------- test 3 ----
10 100
1 2 3 4 5 6 7 8 9 10
------- test 4 ----
25 1000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25
------- test 5 ----
25 9999
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
26
------- test 6 ----
25 9999
346
130
982
1090
1656
7117
7595
6415
2948
1126
9004
4558
3571
2879
8492
1360
5412
6721
2463
5047
7119
1441
7190
3985
1214
------- test 7 ----
25 999
7843
4639
1653
3876
5457
2152
2524
2412
7461
3564
4634
7717
5947
4056
1048
6123
1757
5964
1137
3094
671
5869
2719
631
3563
------- test 8 ----
25 100
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
------- test 9 ----
25 100
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
------- test 10 ----
5 10000
5 8 13 21 34
------- test 11 ----
17 500
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
------- test 12 ----
8 10000
1 2 3 4 5 6 20 25
------- test 13 ----
17 2000
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Keep up the good work!

 

C/C++ LMS算法详解及源码 LMS(Least Mean Squares)算法是一种自适应滤波器算法,用于估计一个系统的参数,以使输出信号与期望信号之间的均方误差最小化。LMS算法通过使用梯度下降的方法,逐步调整自适应滤波器的权值来优化滤波效果。 阅读详情

相关推荐

嵌入式人工智能ESP32(1-初步上手使用)

ESP32还有一个特性是易于开发:ESP32支持Arduino开发环境和MocroPython,开发者可以使用熟悉的Arduino、MicroPython语言和工具进行开发。ESP32还提供了丰富的软件开发工具和文档,方便开发者快速上手。

u010152658的博客 1万+

Money Systems _DP

Money Systems The cows have not only created their own government butthey have chosen to create their own money system. In their own rebellious way,they are curious about values of coinage. Traditi

二方非士的小炒 701

ArcGIS 10.6卸载后残留文件清理全攻略(附10.2安装避坑指南)

本文详细介绍了如何彻底卸载ArcGIS 10.6并安装ArcGIS 10.2的完整解决方案。从标准卸载流程到手动清理残留文件和注册表,再到安装前的准备工作和详细安装步骤,帮助用户避免常见问题,确保降级过程顺利完成。特别强调了清理残留文件和注册表的重要性,以及安装ArcGIS 10.2时的授权配置技巧。

elastic6hunter的博客 883

Money Systems(DP)

Money Systems The cows have not only created their own government but they have chosen to create their own money system. In their own rebellious way, they are curious about values of coinage. Tradit...

Simone chou... 205

【Qt实战项目】记事本完整项目

效果图如下所示: 全部代码如下: #include “notepad.h” #include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.showMaximized(); return a.exec(); }

YIZHILIUSHA2020的博客 589

Field-Oriented Control (FOC) 矢量控制 磁场定向控制

Field-Oriented Control (FOC) 磁场定向控制(FOC),也称为矢量控制,是一种用于控制永磁同步电动机(PMSM)和交流感应电动机(ACIM)的技术。 FOC在整个扭矩和速度范围内都具有良好的控制能力。 FOC的实现需要将定子电流从固定参考系转换为转子磁通参考系(也称为d-q参考系)。 速度控制和转矩控制是FOC最常用的控制模式。位置控制模式不太常见。大多数牵引应用使用转矩控制模式,在该模式下,电动机控制系统遵循参考转矩值。在速度控制模式下,电机控制器遵循参考速度值,并生成用于形成内

>>> 1万+

USACO 2.3 Money Systems 货币系统

Money Systems The cows have not only created their own government but they have chosen to create their own money system. In their own rebellious way, they are curious about values of coinage. Tradi...

NeWorldMaker 273

【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁

【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁

perseverance51博客 1132

USACO Money Systems

1、这是一个完全背包问题,按照《背包九讲》里的来就好,注意最后答案可能为long long型。 /* ID:mrxy564 PROG:money LANG:C++ */ #include #include using namespace std; long long a[30],dp[10010]; int v,n; void CompletePack(int cost,in

407

C++ int转四字节数组

字节转换

我不是码农的博客~~~ 979

YOLOv12 改进 | Backbone改进 3

将CSP中的简单拼接改为可学习的特征选择门控,动态决定哪些特征流向下一层,同样再写这篇。:相比静态CSP的固定50/50分割,门控机制可学习0.3:0.7等最优比例。在输入端加入轻量SR模块,对下采样后的特征进行超分恢复,提升小目标检测能力。(小目标): 从 0.51 AP → 0.63 AP (+24%):采用ESPCN的高效亚像素卷积,避免传统插值的信息损失。:从通道级(SE)到空间级(Spatial)的多粒度控制。:结合浅层细节和深层语义,恢复小目标的纹理信息。

u012133341的博客 846

USACO-Section 2.3 Money Systems(DP)

完全背包问题 对于每一种货币,i单位货币的方案数加上i-a单位货币的方案数:dp[i]+=dp[i-a];

idealism_xxm的专栏 580

LLC设计指南(一)第一章:别一上来就背公式,先把 LLC 的“脾气”摸清楚

很多工程师第一次学 LLC,都会有一种感觉:这个电源拓扑,好像不是在工作,而是在“跳舞”。Buck 很直观,开关一开,电感充电;开关一关,电感放电。Flyback 也好理解,先存能量,再把能量丢给副边。但 LLC 不一样。它不是硬邦邦地把能量“推过去”,而是让电感、电容、变压器一起形成一个谐振网络,让能量在里面来回摆动。控制器再通过调节开关频率,把这个摆动过程“驯服”成稳定输出。这也是 LLC 最迷人的地方:🎯。

weixin_43199439的博客 341

USACO Training Section 2.3 Money Systems

[url="http://ace.delos.com/usacoprob2?a=4iVBI4338BO&S=money"]英文原题[/url] [url="http://www.wzoi.org/usaco/12%5C207.asp"]中文题译[/url] 大意:给定钞票面值,问给定的钱数有多少种付钱方式。 设有m种钞票,每种面值为v[i](0...

山中竹笋 114

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

USACO-Section2.3 Money Systems

USACO-Section2.3 Money Systems

qq_34600424的博客 267

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

USACO-Section2.3 Money Systems【动态规划】

题目描述: 母牛们不但创建了它们自己的政府而且选择了建立了自己的货币系统。由于它们特殊的思考方式,它们对货币的数值感到好奇。 传统地,一个货币系统是由1,5,10,20 或 25,50, 和 100的单位面值组成的。 母牛想知道有多少种不同的方法来用货币系统中的货币来构造一个确定的数值。 举例来说, 使用一个货币系统 {1,2,5,10,…}产生 18单位面值的一些可能的方法是:18x1,...

tjj1998的博客 473

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

USACO section2.3 Money Systems题解&代码

显而易见的完全背包… 很容易看出dp方程为dp[i]+=dp[i-val[j]],其中i是表示的钱数,val[j]是第j个面值,dp[i]是方法数/* ID:rainbow16 LANG:C++ TASK:money */ #include<stdio.h> int n,v,val[30]; long long dp[10005]; int main(void) { freopen("mo

Rainbow6174's home 697

USACO-Money Systems

The cows have not only created their own government but they have chosen to create their own money system. In their own rebellious way, they are curious about values of coinage. Traditionally, coins co

superxtong的博客 593

【USACO】Money Systems

原理在注释里,自己写的不是这样的,参照答案改的。自己写的是最原始版本的DP。但这个推理貌似很厉害的样子,记住之。/* ID : LANG: C++11 TASK: money */ #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #incl...

DreamChaserYx的专栏 358

USACO:Money System

/* ID: Jang Lawrence PROG: money LANG: C++ */ #include #include #include #include #include #define mp make_pair using namespace std; typedef long long lng; lng dp[26][10001]; int n,sum; int a[30]; int

Lawrence_Jang 846

USACO: Money Systems

Money SystemsThe cows have not only created their own government but they have chosen to create their own money system. In their own rebellious way, they are curious about values of coinage. Traditionally, coins come in values like 1, 5, 10, 20 or 25, 50,

351

USACO Money System 背包9讲,动态规划,母函数

一、使用动态规划 (注意阅读dd大神的背包问题九讲) 设dp[i,j]表示前i种货币构成j的方法数,用cc记录货币的面值,状态转移方程为: dp[i,j]=dp[i-1,j];    不用第i种货币 dp[i,j]=dp[i-1,j]+dp[i,j-cc[i]]    用第i种货币,j>=cc[i] 二、构造母函数 也许麻烦了点,但也是一种方法。 原问等价于求一个形如a1X

609

USACO解题思路分析记录(Money System)

USACO题解 Money System 自我步入研究生阶段以来,我就一直打算把自己的编程能力提高,不知道当我真正开始这样做的时候是否已经太晚。毕竟,我已经快25周岁了。我从大约三周前开始决定把USACO的题目刷一遍,之所以这样做,是因为我以前就接触了这个在线评测的网站,当时觉得非常好,但是当时的毅力不行,就没有做出几题就搁置了。当我重新捡起来,已经是许多年后的现在了。

thtfive的专栏 457

usaco Money system

dp这跟我看过的01背包有点区别01背包每件物品只能放一次。这个不是,然后01背包是逆序更新的这个是顺序的 /* ID:jinbo wu TASK:money LANG:C++ */ #include using namespace std; long long f[10005]; int main() { int x; freopen("money.in","r",stdin); fre

silence401的博客 339

P1474 [USACO2.3]Money System / [USACO07OCT]Cow Cash G题解

P1474 [USACO2.3]Money System / [USACO07OCT]Cow Cash G题解 题目传送门 分析: 这道题我们看到货币能无限使用就能够像到这是一道完全背包求方案数问题 我们先设一个ddd数组,did_idi​表示凑成iii的方案数 然后我们就只要考虑一个初始化的问题 因为他只有凑满了iii才能算一种方案,我们就可以就是将d0d_0d0​初始化为1 动态转移方程就很容易推出来了 did_idi​=max(di−w[i]d_{i-w[i]}di−w[i]​+1,did_idi​

FKJDASOI的博客 340

USACO 2.3 Money Systems (money)

//Main idea: //Dynamic Programming //dp[i][j] denote the number of ways to construct money j by coins[0...i] //state transition equation: //dp[i][j] = dp[i-1][j] + dp[i-1][j-coins[i]] + ...dp[i-1][j-

Hello World! 1321
上一篇: USCAO section 2.3 Zero Sum(dfs)
下一篇: USACO section 2.3 Controlling Companies(dfs)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址