当前位置:网站首页>LeetCode 2310. 个位数字为 K 的整数之和
LeetCode 2310. 个位数字为 K 的整数之和
2022-07-02 11:26:00 【HumbleFool】
LeetCode 2310. 个位数字为 K 的整数之和
多重背包DP
const int N = 3010;
class Solution {
public:
int f[N][N], v[N]; //前i个体积不超过j的最小个数
int minimumNumbers(int num, int k) {
int n = 0;
for(int i = k; i <= num; i += 10)
n ++,v[n] = i;
memset(f, 0x3f, sizeof f);
f[0][0] = 0;
for(int i = 1; i <= n; i ++)
for(int j = 0; j <= num; j ++)
{
f[i][j] = f[i - 1][j];
if(j >= v[i])
f[i][j] = min(f[i][j], f[i][j - v[i]] + 1); //注意是f[i][j - v[i]] + 1
}
if(f[n][num] == 0x3f3f3f3f)
f[n][num] = -1;
return f[n][num];
}
};
边栏推荐
- STM32库函数进行GPIO初始化
- Advanced C language (realize simple address book)
- MQ tutorial | exchange (switch)
- 字符串匹配问题
- Method of creating linked server for cross server data access
- 测试框架TestNG的使用(二):testNG xml的使用
- NLA自然语言分析,让数据分析更智能
- Large top heap, small top heap and heap sequencing
- C语言高级用法--函数指针:回调函数;转换表
- Makefile separates file names and suffixes
猜你喜欢
Fundamentals of software testing
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
php链表创建和遍历
Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
<口算練習機 方案開發原理圖>口算練習機/口算寶/兒童數學寶/兒童計算器 LCD液晶顯示驅動IC-VK1621B,提供技術支持
Xilinx Vivado set *. svh as SystemVerilog Header
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
uniapp自动化测试学习
C#代码审计实战+前置知识
随机推荐
Fabric. JS dynamically set font size
Use of freemaker
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
Daily learning 2
String matching problem
Fatal: unsafe repository is owned by someone else
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te
4. Array pointer and pointer array
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
篇9:XShell免费版安装
taobao. logistics. dummy. Send (no logistics delivery processing) interface, Taobao store delivery API interface, Taobao order delivery interface, Taobao R2 interface, Taobao oau2.0 interface
tmall.product.schema.get( 产品信息获取schema获取 ),淘宝店铺上传商品API接口,淘宝商品发布接口,淘宝商品上传API接口,店铺上传接口,oAuth2.0接口
Fabric.js 上划线、中划线(删除线)、下划线
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
Tencent cloud tstor unified storage passed the evaluation of the first batch of basic file storage capabilities of the ICT Institute
[apipost] tutorial
Stm32-dac Experiment & high frequency DAC output test
由粒子加速器产生的反中子形成的白洞