当前位置: 首页 > news >正文

leetcode打卡#day45 携带研究材料(第七期模拟笔试)、518. 零钱兑换 II、377. 组合总和 Ⅳ、爬楼梯(第八期模拟笔试)

携带研究材料(第七期模拟笔试)

#include<iostream>
#include<algorithm>
#include<vector>using namespace std;int main() {int N, V;cin >> N >> V;vector<int> weights(N+1);vector<int> values(V+1);int w, v;for (int i = 0; i < N; i++) {cin >> w >> v;weights.push_back(w);values.push_back(v);}vector<int> pd(N+1, 0);//先遍历背包容量for (int i = 0; i < V; i++) {//再遍历物品for (int j = 0; j < N; j ++) {if (i - weights[j] >= 0) pd[i] = max(pd[i], pd[i-weights[j]] + values[j]);}}cout << pd[V];return 0;}

518. 零钱兑换 II

//不包含顺序
class Solution {
public:int change(int amount, vector<int>& coins) {int n = coins.size();//凑成amount的组合数vector<int> pd(amount + 1, 0);pd[0] = 1;//先遍历物品for (int i = 0; i < n; i++) {//再遍历容量for (int j = coins[i]; j <= amount; j++) {pd[j] += pd[j - coins[i]];}}return pd[amount];}
};

377. 组合总和 Ⅳ

//包含顺序
class Solution {
public:int combinationSum4(vector<int>& nums, int target) {//目标为i的组合数vector<int> dp(target+1, 0);int n = nums.size();dp[0] = 1;//先容量再物体 -- 排序数for (int i = 0; i <= target; i++) {//遍历背包for (int j = 0; j < n; j++) {if (i - nums[j] >= 0 && dp[i] < INT_MAX - dp[i - nums[j]]) dp[i] += dp[i - nums[j]];}}return dp[target];}
};

爬楼梯(第八期模拟笔试)

#include<iostream>
#include<algorithm>
#include<vector>using namespace std;int main() {int m, n;cin >> n >> m;vector<int> dp(n+1, 0);dp[0] = 1;//包含顺序,排序:先容量再物品for (int i = 0; i <= n; i++) {for (int j = 1; j <= m; j++) {if (i - j >= 0) dp[i] += dp[i - j];}}cout << dp[n] << endl;return 0;
}
http://www.lryc.cn/news/375810.html

相关文章:

  • Vite+Vue3安装且自动按需引入Element Plus组件库
  • 敬酒词大全绝对实用 万能敬酒词
  • 【Java】已解决com.mysql.cj.jdbc.exceptions.CommunicationsException异常
  • Leetcode 76. 最小覆盖子串
  • JAVAWEB--Mybatis03
  • 论文学习_Fuzz4All: Universal Fuzzing with Large Language Models
  • 元数据相关资料整理 metadata
  • 【Android面试八股文】谈一谈你对http和https的关系理解
  • Vue3 中 setup 函数与 script setup 用法总结
  • Springboot 开发之任务调度框架(一)Quartz 简介
  • 企业中面试算法岗时会问什么pytorch问题?看这篇就够了!
  • 【学习】程序员资源网址
  • 【3D模型库】机械三维模型库整理
  • 基于Python-CNN深度学习的物品识别
  • Qt | 简单的使用 QStyle 类(风格也称为样式)
  • Idea连接GitLab的过程以及创建在gitlab中创建用户和群组
  • 关于glibc-all-in-one下载libc2.35以上报错问题
  • C语言之#define #if 预处理器指令
  • modbus流量计数据解析(4个字节与float的换算)
  • 关于element-plus中el-select自定义标签及样式的问题
  • 硕思logo设计师下载-2024官方最新版-logo制作软件安装包下载
  • springboot和mybatis项目学习
  • simdjson 高性能JSON解析C++库
  • 安卓Context上下文
  • 实验13 简单拓扑BGP配置
  • 面试题分享--Spring02
  • 基于QT和C++实现的中国象棋
  • Mojo崛起:AI-first 的编程语言能否成为新流行?
  • 【数据结构与算法】哈夫曼树与哈夫曼编码
  • 基于多头注意力机制卷积神经网络结合双向门控单元CNN-BIGRU-Mutilhead-Attention实现柴油机故障诊断附matlab代码