当前位置:网站首页>Dynamic programming: coin topic summary
Dynamic programming: coin topic summary
2022-04-21 17:38:00 【yilyil】
-
arr Currency array , Where the values are integers . Give another integer aim, Each value is considered a currency , Even if the value of the same currency, it is considered that each one is different , return amin The number of ways
-
arr Currency array , Where the values are non repeating integers . Give another integer aim, The number of sheets per currency is unlimited , return amin The number of ways
-
arr Currency array , Where the value can be a repeating integer . Give another integer aim, Every identical value is considered to be the same currency , return amin The number of ways
-
arr Currency array , Where the values are non repeating integers . Give another integer aim, The number of sheets per currency is unlimited , Return composition aim Minimum number of sheets
From the trial model

From the trial code ( Trying to model leads to )
public static int process(int[] arr, int index, int rest) {
if (rest < 0) {
return 0;
}
if (index == arr.length) {
// No money. !
return rest == 0 ? 1 : 0;
}
return process(arr,index+1,rest)+process(arr,index+1,rest-arr[index]);
}
public static int process(int[] arr, int index, int rest) {
if (index == arr.length) {
return rest == 0 ? 1 : 0;
}
int ways = 0;
for (int zhang = 0; zhang * arr[index] <= rest; zhang++) {
ways += process(arr, index + 1, rest - (zhang * arr[index]));
}
return ways;
}
public static int process(int[] coins, int[] num, int index, int rest) {
if (index == coins.length) {
return rest == 0 ? 1 : 0;
}
int ways = 0;
for (int zhang = 0; zhang * coins[index] <= rest && zhang <= num[index]; zhang++) {
ways += process(coins, num, index + 1, rest - (zhang * coins[index]));
}
return ways;
}
public static int process(int[] arr, int index, int rest) {
if (index == arr.length) {
return rest == 0 ? 0 : Integer.MAX_VALUE;
} else {
int ans = Integer.MAX_VALUE;
for (int zhang = 0; zhang * arr[index] <= rest; zhang++) {
int next = process(arr, index + 1, rest - zhang * arr[index]);
if (next != Integer.MAX_VALUE) {
ans = Math.min(ans, zhang + next);
}
}
return ans;
}
}
from dp Watch , Try model code

版权声明
本文为[yilyil]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211737496740.html
边栏推荐
- Conception d'un cas d'essai basé sur l'interface de chiffrement pour le forage pratique de marchandises sèches
- [interview ordinary people vs Expert Series] understanding of B tree and B + tree
- A field set by MySQL cannot be duplicate
- 本田北美产品规划发布!Insight混动停产,CR-V、雅阁即将发布
- 理想ONE终于换代?全新产品序列定名L8,重度伪装路试照曝光
- C ODBC loads the files of one folder into the blob column of MySQL database and downloads the blob column to another folder
- Insight technology passed the "federal learning" product evaluation of the national financial technology evaluation center of the central bank in the first batch, realizing the dual certification of "
- Fixturlaser对中仪维修GO/NXA Pro/ECO/EVO系列
- SSD_ RESNET aircraft and oil drum data set actual combat
- 【面试普通人VS高手系列】b树和b+树的理解
猜你喜欢
Introduction to MySQL ODBC driver

Image Manipulation Detection by Multi-View Multi-Scale Supervision

Fixturlaser对中仪维修GO/NXA Pro/ECO/EVO系列
![[stack] 155 Minimum stack](/img/48/66e69d25e55dd3f568dd87af74fe05.png)
[stack] 155 Minimum stack

短视频APP相关推荐资源位的高扩展高可用工程实践

5000 movie datasets from tmdb

Spark SQL底层执行流程详解
![[interview ordinary people vs Expert Series] understanding of B tree and B + tree](/img/b9/d648a0da059713ba5ac139dbfad2cd.png)
[interview ordinary people vs Expert Series] understanding of B tree and B + tree
理想ONE终于换代?全新产品序列定名L8,重度伪装路试照曝光

【一篇文章帮你打好路由基础】
随机推荐
The second spring of NFT sector - everything you need to know about the early layout of Solana's rising NFT ecosystem
[an article helps you lay a good foundation for routing]
. net core enterprise wechat web page authorization login
俄乌冲突引发顾虑 五眼网络安全部门建议盟友增强关键基础设施防护
About the internal supposition
Redis三种模式——主从复制,哨兵模式,集群
Insight technology passed the "federal learning" product evaluation of the national financial technology evaluation center of the central bank in the first batch, realizing the dual certification of "
What is ODBC – open database connectivity
Wx open launch web app style problem
Authentication bypass vulnerability in JIRA seraph (cve-2022-0540)
直播app源码,在无法显示图片的基础上添加图片显示功能
C# ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
No more simple intention lock
MySQL advanced common functions
short_open_tag 短开放标签 必须打开
MySQL数据库常识之储存引擎
5000 movie datasets from tmdb
基于SSM的美容院管理系统(附源码+项目展示)
动态规划:硬币题目总结
我用Ehcache把查询性能提升了100倍,真香