当前位置:网站首页>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];
}
};
边栏推荐
- Reuse and distribution
- The use of TestNG, the testing framework (II): the use of TestNG XML
- Fabric.js 上划线、中划线(删除线)、下划线
- MQ教程 | Exchange(交换机)
- What is erdma? Popular science cartoon illustration
- 测试框架TestNG的使用(二):testNG xml的使用
- STM32 standard firmware library function name (I)
- Simple verification code generator for 51 single chip microcomputer experiment
- Factal: Unsafe repository is owned by someone else Solution
- A white hole formed by antineutrons produced by particle accelerators
猜你喜欢

Fabric.js 缩放画布

Quick analysis: easy to share the Internet

Tmall product details interface (APP, H5 end)

Yyds dry goods inventory software encryption lock function

Pychart connects to the remote server

< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621

Method of creating linked server for cross server data access

PHP linked list creation and traversal

fatal: unsafe repository is owned by someone else 的解决方法

There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '
随机推荐
Fundamentals of software testing
MQ教程 | Exchange(交换机)
Makefile 分隔文件名与后缀
Certik released the defi security report in 2021, disclosing key data of industry development (PDF download link attached)
Check password
ONNX+TensorRT:将预处理操作写入ONNX并完成TRT部署
buuctf-pwn write-ups (7)
tmall.product.schema.get( 产品信息获取schema获取 ),淘宝店铺上传商品API接口,淘宝商品发布接口,淘宝商品上传API接口,店铺上传接口,oAuth2.0接口
freemarker的使用
STM32 library function for GPIO initialization
php链表创建和遍历
Xilinx Vivado set *.svh as SystemVerilog Header
NLA自然语言分析,让数据分析更智能
QT new project
《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持
实现一个多进程并发的服务器
Why can't browsers read JSX?
String matching problem
Understanding of mongodb
The use of TestNG, the testing framework (II): the use of TestNG XML