[Algorithm] Max icons to include: Dynamic programming
to max Dynamic Programming ALGORITHM include
2023-09-14 09:00:46 时间
Saying that we have some icons
and a target sum, for example 16.
How to choose which and how many icons to include to reach the target but minize the numbers of icons.
EXP: 3 * 5$ icons
+
1 * 1$icon
-------------
total 4 icons.
Idea is
Wheather should include current icon.
const Pair = (i, t) => `Pair(${i}, ${t})`; const iconsToInclude = (nums, total) => { let cache = {}; const doWork = (i, t) => { const p = Pair(i, t); if (p in cache) { return cache[p]; } if (i === 0 || t === 0 || nums[i] > t) { return Number.MAX_SAFE_INTEGER; } if (t === 1 || nums[i] === t) { return 1; } let toInclude = 0 let notToInclude = 0; let res = 0; toInclude = doWork(i, t - nums[i]) + 1; notToInclude = doWork(i - 1, t); res = Math.min(toInclude, notToInclude); cache[Pair(i, t)] = res; return res; } return doWork(nums.length - 1, total); } console.log(iconsToInclude([25, 16, 5, 1], 33));
相关文章
- Failed to configure a DataSource
- ORA-24342: unable to destroy a mutex ORACLE 报错 故障修复 远程处理
- ORA-27213: failed to unload Media Management Library ORACLE 报错 故障修复 远程处理
- ORA-00364: cannot write header to new log member ORACLE 报错 故障修复 远程处理
- ORA-00849: SGA_TARGET string cannot be set to more than MEMORY_MAX_TARGET string. ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-010428; Symbol: ER_RPL_SLAVE_FAILED_TO_CREATE_CHANNEL_FROM_MASTER_INFO; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-06730: TLI Driver: unable to open clone device ORACLE 报错 故障修复 远程处理
- ORA-10586: Test recovery had to corrupt 1 data block in order to proceed ORACLE 报错 故障修复 远程处理
- ORA-12811: PARALLEL_MIN_SERVERS must be less than or equal to PARALLEL_MAX_SERVERS, string ORACLE 报错 故障修复 远程处理
- ORA-16444: ALTER SYSTEM FLUSH REDO TO STANDBY failed due to a corrupted control file or online log file. ORACLE 报错 故障修复 远程处理
- ORA-19012: Cannot convert XML fragment to the required datatype ORACLE 报错 故障修复 远程处理
- oracle使用to_date查询一周的第一天日期
- FunDA(0)- Functional Data Access accessible to all详解编程语言
- functionMySQL ABS Function: the Solution to Mathematics Problems.(mysqlabs)
- ECC TO HANA FAGLB03 search-help on Account Number field doesn’t working or not returning the selected value to the Account Number field.详解编程语言
- Pika Redis: An Introduction to This HighPerformance KeyValue Database(pikaredis)
- 深入解析MySQL中MAX函数的使用方法(mysql中max的用法)
- 极致的比较Oracle vs Max(max 比较oracle)
- 中文Oracle极致发挥MAX(max中文 oracle)
- 函数Oracle数据库极大值函数MAX的使用(oracle使用max)
- 红遍大街小巷,去用Redis吧(to go redis)
- 利用 Oracle Max 去除重复项(oracle max去重)
- 数据表 Oracle MAX 合并两个数据表的实践研究(oracle max两个)
- Oracle MAX 勇往直前,超越自我(oracle max 1)