刷题笔记:力扣第78、79、90题(子集查找)

全网最全医学图像数据汇总 本仓库汇总了多个领域的医学图像开源数据集,涵盖CT、MRI、超声、内窥镜、病理、多模态、PET、OCT以及皮肤镜等多种成像技术。每个数据集均详细列出了任务类型、部位、格式、数量及下载链接,旨在为医学图像研究者提供便捷的资源导航。⚠️:这些数据集仅适用于学术研究用途。 阅读详情

力扣第78题-子集

1.题目不难理解,这是一道排列组合问题,每个数组元素都可以选择在子集中或者不在子集中,所以最终的子集个数为2^numsSize个。想到可以使用递归算法,将所有选择都能遍历到。完整代码如下:

 1. // 全局变量定义
 2. int** res;          // 存储最终所有子集的结果数组
 3. int resSize;        // 当前结果集中的子集数量
 4. int* path;          // 存储当前正在构建的子集
 5. int pathSize;       // 当前子集的元素个数
 6. int* col;           // 存储每个子集的长度(对应 returnColumnSizes)
 7.  
 8. void dfs(int cur, int* nums, int numsSize){
 9.     // ====================== 递归终止条件 ======================
10.     // 当遍历完所有元素(cur == numsSize)时,将当前 path 加入结果集
11.     if (cur == numsSize){
12.         // 为当前子集分配内存并复制 path 内容
13.         int* tmp = (int*)malloc(sizeof(int) * pathSize);
14.         memcpy(tmp, path, sizeof(int) * pathSize);
15.         // 记录当前子集的长度
16.         col[resSize] = pathSize;
17.         // 将子集存入结果集,并将结果集计数 +1
18.         res[resSize++] = tmp;
19.         return;
20.     }
21.  
22.     // ====================== 决策1:选择当前元素 nums[cur] ======================
23.     // 将当前元素加入 path
24.     path[pathSize++] = nums[cur];
25.     // 递归处理下一个元素
26.     dfs(cur + 1, nums, numsSize);
27.  
28.     // ====================== 决策2:不选择当前元素 nums[cur](回溯) ======================
29.     // 撤销选择:将当前元素从 path 中移除
30.     pathSize--;
31.     // 递归处理下一个元素
32.     dfs(cur + 1, nums, numsSize);
33. }
34.  
35. int** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
36.     // 初始化全局变量,避免多次调用时残留数据
37.     resSize = 0;
38.     pathSize = 0;
39.  
40.     // 计算子集总数:2^numsSize(注意:实际工程中建议用 1 << numsSize 替代 pow 避免精度问题)
41.     int cntMax = pow(2, numsSize);
42.  
43.     // 为结果集、子集长度数组、当前子集路径分配内存
44.     res = (int**)malloc(sizeof(int*) * cntMax);
45.     col = (int*)malloc(sizeof(int) * cntMax);
46.     path = (int*)malloc(sizeof(int) * numsSize);
47.  
48.     // 从第 0 个元素开始 DFS 生成所有子集
49.     dfs(0, nums, numsSize);
50.  
51.     // 设置返回参数
52.     *returnSize = resSize;
53.     *returnColumnSizes = col;
54.  
55.     return res;
56. }

该算法的时间复杂度为O(n × 2ⁿ),空间复杂度为O(n),属于本题的标准解法。

2.在算法中使用了memcpy函数,它的函数声明如下:

1. void *memcpy(void *dest, const void *src, size_t num);

因为最后一个参数是复制的字节数,所以本题中该参数为sizeof(int) * pathSize。相比于strcpy函数,memset函数不会遇到’\0’就停止。

另外还有常用的memset函数,它的函数声明如下:

1. void *memset(void *ptr, int value, size_t num);

值得注意的是,memset函数是给每个字节进行幅值,所以不能给int数组赋0以外的值,比如赋值为1,因为int占4个字节,所以每个int元素就会变成0x01010101,不是1!

3.在dfs函数中不断地进行空间开辟,将指向这片空间的指针命名为tmp,之后对tmp指向的空间进行赋值,res[resSize++] = tmp是将指向刚刚那块新内存的地址存到结果数组,所以在下次递归时tmp指向别的内存也没有问题。

4.对于递归问题自己掌握的并不是太好,目前拿到题目能有一定的思路,但对于如何构建递归函数并不能每次写对。咨

4、高级认证解决方案:Active Directory、LDAP、RADIUS和TACACS+深度解析 本文深入解析了多种高级认证解决方案,包括Active Directory、标准LDAP、RADIUS和TACACS+,涵盖其技术优势、配置步骤及适用场景。同时介绍了如何实现通用用户管理,包括使用第三方认证解决方案和ADSI自助用户管理。通过实际案例部署,展示了如何高效、安全地管理大规模用户认证与权限控制,为企业安全架构提供参考。 阅读详情

相关推荐

4×V100部署Qwen3.8-Flash-Next:vLLM/GGUF实战

大模型本地部署的核心,是把参数量、量化精度、显存容量和推理框架放在同一张账本里算清楚。MoE 模型总参数量大但激活参数少,解码阶段更受显存带宽与 KV Cache 限制;通过 INT4/AWQ 或 GGUF 等 4-bit 量化可显著压缩权重占用,再结合 vLLM 张量并行、llama.cpp 分层切分提升多卡利用率。其技术价值在于让 V100 这类老架构 GPU 也能承载百亿级参数模型的私有化推理,并服务于 RAG 知识库、工作流 API、批量生成等场景。这次围绕 4×V100 32G 部署 Qwen3.

weixin_29061425的博客 363

电机FOC控制实战:STM32 CubeMX配置六路互补PWM与死区优化

本文详细介绍了如何使用STM32 CubeMX配置六路互补PWM与死区优化,实现电机FOC控制。通过实战经验分享,包括时钟配置、定时器设置、死区时间计算及优化技巧,帮助开发者避免常见问题,提升电机控制性能。特别适用于STM32G4系列的无刷电机驱动应用。

weixin_29193259的博客 409

2d游戏地图编辑器_[U3D]基于MarchingCubes实现的War3Editor 地表/悬崖编辑器

花了几天时间研究清楚Marching cubes后,发现这个方法是一个非常适用于地图编辑,网格编辑,procedural 生成的工具。最大的优点有着较好的边缘,表面处理。然后我用U3D写了一个悬崖/地表的编辑器。其中使用到了Marching Cubes的2.5D,2D两种降维的方法。talk is cheap,让我看效果!DemoEditor展示https://www.zhihu.com/vide...

weixin_42504649的博客 1183

Polyworks脚本开发实战指南:高效生成数据彩图与报告的关键指令解析

本文深入解析了Polyworks脚本开发中生成数据彩图与自动化报告的核心指令。通过实战案例,详细介绍了REFERENCE_SURFACE、THICKNESS和CLEARANCE等关键彩图生成指令的正确用法与常见避坑点,并阐述了如何利用REPORT_ITEM命令实现从截图、表格生成到智能排版的全流程自动化,旨在帮助三维检测与质量控制工程师大幅提升工作效率与报告标准化水平。

weixin_29209825的博客 571

uniapp+coze制作app智能体

使用 UniApp 配合 Coze 平台来开发一个具备 AI 智能体的 App,是一个高效且实用的选择。其核心思路主要有两种:一种是通过,另一种则是通过实现更自主的集成。下面的流程图可以帮你快速了解这两种方案的全貌。下面,我们来详细看看这两种方案分别如何操作。

suny8的专栏 579

自然语言处理:长文本场景下的关键词抽取实践

自然语言处理:长文本场景下的关键词抽取实践

丨汀、的博客 2082

Matlab之App Designer 如何进行三维图形绘制教程

基于Matlab中的App Designer设计可视化界面并进行数据导入及3D绘图,可以直观的在可视化界面上展示分析结果,方便用户进行图形的操作。本文采用案例讲解的方式,详细介绍了如何采用Matlab App Designer建立数据3D绘图的GUI可视化界面的方法和详细的过程步骤,并介绍了导入数据进行计算时需要注意的相关事项,同时提供了详细的代码,以便读者进行学习和操作。

m0_59012156的博客 2071

本地通知与健康数据的隐私保护方案

随着移动健康(mHealth)应用的普及,本地通知与健康数据的结合为用户提供了更加个性化的健康管理体验。然而,这种便利性也带来了严峻的隐私保护挑战。本文旨在探讨如何在移动应用中实现本地通知功能的同时,确保用户健康数据的隐私安全。本地通知与健康数据结合的技术架构隐私保护的核心技术方案具体算法实现与数学模型实际应用案例分析本文首先介绍背景知识和核心概念,然后深入探讨隐私保护的技术方案,包括算法原理和数学模型。接着提供实际代码实现和应用场景分析,最后讨论未来发展趋势和挑战。

移动开发前沿的博客 1314

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

上一篇: 刷题笔记:力扣第75题-颜色分类
下一篇: 刷题笔记:力扣第80题-删除有序数组中的重复项Ⅱ
hanlin03
博客等级 码龄5年 12粉丝 128原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值