华为OD机试 C++【月饼分配方案计数】

题目

中秋节,公司分月饼,m 个员工,买了 n 个月饼,m ≤ n,每个员工至少分 1 个月饼,但可以分多个,

  • 单人分到最多月饼的个数是 Max1 ,单人分到第二多月饼个数是 Max2 ,Max1 - Max2 ≤ 3 ,
  • 单人分到第 n - 1 多月饼个数是 Max(n-1),单人分到第n多月饼个数是 Max(n) ,Max(n-1) – Max(n) ≤ 3,

问有多少种分月饼的方法?

输入描述
每一行输入m n,表示m个员工,n个月饼,m ≤ n

输出描述
输出有多少种月饼分法

用例

输入	
2 4
输出	
2

解题思路

我们需要将 n 个月饼分配给 m 个员工,要求每个员工至少分 1 个月饼,并且相邻员工之间分配的月饼数差距不超过 3。可以通过递归的方法来解决这个问题,确保每个员工分配到的月饼数是升序的且相邻数值之间的差不超过 3。

代码

#include 
华为OD机试 Python【月饼分配方案计数】 将 n 个月饼分配给 m 个员工,要求每个员工至少分 1 个月饼,并且相邻员工之间分配的月饼数差距不超过 3。可以通过递归的方法来解决这个问题,确保每个员工分配到的月饼数是升序的且相邻数值之间的差不超过 3。中秋节,公司分月饼,m 个员工,买了 n 个月饼,m ≤ n,每个员工至少分 1 个月饼,但可以分多个,每一行输入m n,表示m个员工,n个月饼,m ≤ n。问有多少种分月饼的方法?输出有多少种月饼分法。 阅读详情

相关推荐

华为OD机试 - 分月饼 - 回溯(Java 2024 D卷 200分)

递归是一种算法设计技术,通过在函数内部调用自身来解决问题,通常涉及将问题分解为更小的子问题,并在基本情况下终止,常用于解决具有自相似结构的问题。

学Java,找哪吒 5729

2026年华为od机试真题题库

OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)

面试高手的博客 19万+

2026华为OD机试(Python)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,Python实现。

MISAYAONE的博客 29万+

【华为OD机试真题 C++语言】363、分月饼 | 机试真题+思路参考+代码解析(C卷)

>公司分月饼,m个员工,买了n个月饼,m

KJ.JK 3288

【华为OD机试真题 2025C卷】839、分月饼 | 机试真题+思路参考+代码分析(C++、Java、Py、C语言、JS)

【华为OD机试真题 2025C卷】839、分月饼 | 机试真题+思路参考+代码分析(C++、Java、Py、C语言、JS) 华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2025e卷,od机试,2025E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2025华为od,如何备战华为od,

KJ.JK 2857

华为OD机试双机位C卷-分月饼(C/C++/Py/Java/Js/Go)

华为OD机试双机位C卷 【分月饼】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。华为OD机试真题【分月饼】。

qq_45776114的博客 1036

华为OD机试 新系统 双机位C卷 往年真题 机考题库(持续收录中)以及算法考点详解(Python/JS/C/C++)

刷的越多,抽中的概率越大,每一题都有详细的答题思路、详细的代码注释发现新题目,随时更新。

学Java,找哪吒 5万+

2024华为OD机试真题题库目录(E卷&A卷&B卷&C卷&D卷)

2023年最新华为机试题库,每道题有详细讲解。

wtswts1232的博客 6万+

【2024华为OD机试C卷】363、分月饼 | 机试真题+思路参考+代码解析(C语言、C++、Java、Py、JS)

题目描述 >公司分月饼,m个员工,买了n个月饼,m

KJ.JK 1882

2026华为OD机试(C语言)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,C语言实现。

MISAYAONE的博客 11万+

2026华为OD机试(JavaScript)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,JavaScript实现。

MISAYAONE的博客 8万+

2026华为OD机试(JAVA&Go)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,Java实现。

MISAYAONE的博客 34万+

华为OD机试 - 分月饼 - 回溯(Python/JS/C/C++ 2024 D卷 200分)

递归是一种算法设计技术,通过在函数内部调用自身来解决问题,通常涉及将问题分解为更小的子问题,并在基本情况下终止,常用于解决具有自相似结构的问题。

学Java,找哪吒 859

2026华为OD机试(C++)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,C++实现。

MISAYAONE的博客 20万+

LLMOps的崛起:如何利用Langfuse和Opik构建高效的模型监控与评估体系

本文探讨了LLMOps的崛起,详细介绍了如何利用Langfuse和Opik构建高效的模型监控与评估体系。通过开源工具Langfuse的全景监控方案和Opik的三层评估体系,帮助AI工程团队实现大语言模型的全生命周期管理,提升模型性能和迭代效率。文章还提供了实战技巧和工具链集成方案,助力企业优化AI应用。

ll5678的博客 682

《AI应用架构师智能特征工程实践的前沿趋势解读》

面对传统方法的局限性,智能特征工程(Intelligent Feature Engineering)应运而生。智能特征工程是指利用人工智能、机器学习和自动化技术,实现特征提取、构造、选择和优化过程的自动化、智能化和可扩展化的方法和技术体系。效率提升:将数据科学家从繁琐的人工特征工程中解放出来,大幅缩短特征开发周期。质量保障:通过系统化方法发现人类难以察觉的特征模式,提高特征质量和模型性能。可扩展性:能够处理大规模、高维度和多类型的数据,适应不同领域和场景。降低门槛。

大数据洞察的博客 1182

Qt for Android:基于libusb实现CH340x串口通信的高效开发方案

本文详细介绍了在Qt for Android环境下,基于libusb实现CH340x串口通信的高效开发方案。通过绕过Android高版本系统的权限限制,利用libusb+JNI技术实现稳定通信,适用于工业手持终端等场景。文章涵盖环境搭建、核心实现、常见问题解决方案及性能调优经验,帮助开发者快速掌握这一关键技术。

weixin_42715608的博客 428

图神经网络实战(8)——图注意力网络(Graph Attention Networks, GAT)

图注意力网络 (Graph Attention Networks, GAT) 是对图卷积网络 (Graph Convolutional Network, GCN) 的改进,提出了一种通过自注意力 (self-attention) 过程计算的加权因子,而不是使用静态的归一化系数。在本节中,我们介绍了 GAT 架构。通过从线性变换到多头注意力的四个主要步骤,了解了 GAT 的工作原理,并在 NumPy 中从零开始构建了 GAT 层。最后,将 GAT 模型应用于 Cora 和 CiteSeer 数据集。

盼小辉丶的博客 1万+

OpenCode + Oh My OpenCode:打造你的终极AI编程团队(OpenCode新手入门指南)

本文详细介绍了开源终端AI编程助手 OpenCode 的完整配置教程 🖥️,从安装、AI模型配置到增强插件 Oh My OpenCode 的部署一应俱全。支持 Claude、ChatGPT、Gemini 多模型切换 🤖,还能实现多AI智能体协作开发。步骤清晰适合新手 📝,想在终端用AI写代码的开发者不要错过 ✨

XiaoqiangClub的博客 1万+

高通拨号流程介绍

本文介绍了高通平台(如SDX55)中APSS(A7处理器)与ModEM(Q6处理器)间的通信机制。

四儿家的小祖宗的博客 1068

华为OD机试真题 新系统【小花获胜的奶茶】

华为OD机试真题 新系统【小花获胜的奶茶】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【小花获胜的奶茶】多语言题解。

qq_45776114的博客 399

【路径规划】Theta_star算法机器人栅格地图最短路径规划【含Matlab源码 2618期】

Theta_star算法机器人栅格地图最短路径规划 完整的代码,方可运行;可提供运行操作视频!适合小白!

订阅付费专栏Matlab(奶茶价版),可赠送奶茶价版付费专栏指定代码1份; 365

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 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")

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

上一篇: 华为OD机试 Java【月饼分配方案计数】
下一篇: 华为OD机试 Python【月饼分配方案计数】
AlgorithmHero
博客等级 码龄4年 606粉丝 1067原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AlgorithmHero

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值