【JZOJ 4806】打工

算法面经手撕系列(2)--手撕BatchNormlization 手动实现/手撕BatchNormlization 阅读详情

Description

这里写图片描述

Solution

从高位往低位做,可以用一个很显然的DP方程:设f[i][j]表示做到第i位,有j种不同的分组,并且低于输入的有多少种。
转移显然:从上一位新增或者当前局限扩展;再把当前最大的扩展上去。

复杂度:O(n2)

Code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long LL;
const int N=10500,mo=1e6+7;
int read(int &n)
{
    char ch=' ';int q=0,w=1;
    for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
    if(ch=='-')w=-1,ch=getchar();
    for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int n,ans;
int a[N],b[N];
long long f[2][N];
int main()
{
    int q,w;
    read(n);
    fo(i,1,n)b[i]=max(b[i-1],read(a[i]));
    fo(I,1,n)
    {
        int i=I%2;
        fo(j,1,I)f[i][j]=(f[!i][j]*j%mo+f[!i][j-1])%mo;
        f[i][b[I-1]]=(f[i][b[I-1]]+a[I]-1)%mo;
    }
    ans=0;
    fo(i,1,n)ans=(ans+f[n%2][i])%mo;
    printf("%d\n",ans+1);
    return 0;
}
《YOLOv8-seg改进》专栏指导书册 &手把手创新教程 学姐带你学习YOLOv8,从入门到创新,轻轻松松搞定科研;1)手把手教你如何训练YOLOv8-seg;2)模型创新,提升分割性能;3)独家自研模块助力分割; 阅读详情

相关推荐

Claude Desktop Cowork国内实操指南:本地文件自动化办公

大语言模型正从‘问答式AI’迈向‘执行型协作者’,其核心能力在于直接操作本地文件、调用系统工具并嵌入真实工作流。Claude Desktop的Cowork模式正是这一范式的代表,它通过轻量沙箱VM实现对Excel、PPT、PDF、音视频等办公资产的读写与处理,无需手动编码即可完成数据清洗、会议纪要生成、自动化报告输出等任务。技术价值体现在权限可控、环境隔离、结果可交付;典型场景覆盖行政文秘的文档流转、销售运营的数据分析、开发者的脚本调试与环境验证。本文聚焦国内用户高频卡点——网络链路、系统权限与工作流断层,

weixin_30617737的博客 468

JZOJ 4806 【NOIP2016提高A组五校联考3】打工

打工题目大意题目有点长。数据范围对于100100%的数据,NN≤1000010000。题解设Fi,j,kF_{i,j,k}表示当前编号为11~ii的人已经完成分配,且分配方案合法,分配了jj队,且第11~ii的人的编号组成的序列的字典序小于(kk=00)或等于(kk=11)原序列第11~ii个人的编号组成的字典序时,分配的方案数。 转移比较显然,请读者自行思考,也可参考程序。 由于空间复杂度可能

XianHaoMing的博客 2716

DELL服务器BIOS下配置RAID阵列

dell服务器配置raid阵列

weixin_58250887的博客 1万+

JZOJ4806. 打工

Description Input第一行,一个整数N表示参赛人数。 第二行,N个整数,表示询问的分队方式的序列。Output一行,一个整数表示这种方式会在第几天被采用。答案对1,000,007取模。Sample Input3 1 2 2Sample Output4Data Constraint 对于100%的数据,N ≤ 10000 , 数据保证询问的数列是一个有效的序列。 详细情况见下表

lijf2001的博客 1959

光学系统设计:波段、光源、光纤与探测器匹配指南

在光学测量和光纤通信系统中,波段、光源、光纤和探测器的匹配关系是系统设计的核心基础。波段指电磁波谱中的特定波长范围,光源负责产生特定波长的光信号,光纤作为传输介质需要与波长匹配以降低损耗,探测器则负责将光信号转换为电信号。理解各组件的光谱特性对于系统性能至关重要,例如在850nm短波长多模光纤系统中,VCSEL激光器与PIN光电二极管的组合能提供最佳性价比。典型应用场景包括生物医学成像、光纤通信和气体传感,其中光谱重叠优化、模场直径匹配和偏振特性协调是关键技术要点。通过实测数据对比不同组合的传输性能,可以为

weixin_33812433的博客 338

Delphi开发者必备:CEF4Delphi跨平台浏览器嵌入实战指南(含Lazarus适配)

本文详细介绍了Delphi开发者如何利用CEF4Delphi实现跨平台浏览器嵌入,包括环境配置、Lazarus适配、ARM架构优化及Firemonkey集成等实战技巧。通过Chromium引擎的强大功能,开发者可以轻松为传统桌面应用添加现代浏览器特性,提升多平台开发效率。

weixin_29233333的博客 226

【JZOJ4806】打工

【JZOJ4806】题解

sadnohappy 420

SAP-MM-供应商对账平台(功能集合)

(1)集成OA审批,线上核销,结果写入SAP; (2)集成SRM,线上与供应商对账确认,写入SAP; (3)集成财务付款结果确认写入,OA回传结果,定时同步SRM供应商平台。 欢迎留言交流,功能完善,如需要页面设计,请订阅专栏

qq_32198063的博客 748

JZOJ 4806. 打工

DP

Luckfort 386

dify进阶:使用 FastAPI 的 StreamingResponse 实现高效的数据流传输

在 FastAPI 框架中,是一个非常有用的工具,它允许你以流的方式发送数据给客户端,而不是一次性加载所有内容到内存中再发送。这对于处理大型文件下载、视频流或者任何需要长时间处理的任务特别有用。

xiezhipu的博客 1433

FM收音机调试-RDA5807M

收音机调试 IC型号:RDA5807M

mangofu的博客 6164

【JZOJ 4806】【NOIP2016提高组 五校联考3】打工

Description 对于100%的数据,N ≤ 10000 , 数据保证询问的数列是一个有效的序列。Analysisdp显然 f[i][j]f[i][j]表示做到第i个,前面填的数最大的为j的答案 f[i][j]=f[i−1][j]∗k+f[i−1][j−1]+g[i−1][j]∗(a[i]−1)f[i][j]=f[i-1][j]*k+f[i-1][j-1]+g[i-1][j]*(a[i]

LYD729 573

C/C++ LMS算法详解及源码

LMS(Least Mean Squares)算法是一种自适应滤波器算法,用于估计一个系统的参数,以使输出信号与期望信号之间的均方误差最小化。LMS算法通过使用梯度下降的方法,逐步调整自适应滤波器的权值来优化滤波效果。

希望我的博客,能帮上你解决学习中工作中所遇到的问题 3276

做的中等题,难题总结【6~7月】

jzoj4612. 【NOIP2016模拟7.12】游戏(中等题) 将每一个空格看作边,与每一个划分出来的长条连边作二分图匹配,注意软石头也要被划分不然长条编号不对 jzoj4224. 【五校联考3day1】食物(中等题) 注意到预算和美味度都 $\leq 50000$,于是作状态互换dp,多重背包要用单调队列优化 jzoj4631. 【GDOI2017模拟7.15】背单词(中等题) 可...

weixin_30871905的博客 271

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

【NOIP 2016 提高组】愤怒的小鸟

DescriptionSolution一题很显然的状压DP, 显然的转移是n3n^3的, 优化: 1. 很显然两个点决定一条抛物线后,可以预处理还能打到那些点。 2. 贪心的想,既然一个点迟早要打,为何不现在就打了它,复杂度:O(2n∗n)O(2^n*n)Code#include <iostream> #include <cstdio> #include <cstdlib> #include

1482

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

【JZOJ 3853】帮助Bsny

DescriptionBsny的书架乱成一团了,帮他一下吧! 他的书架上一共有n本书,我们定义混乱值是连续相同高度书本的段数。例如,如果书的高度是30,30,31,31,32,那么混乱值为3;30,32,32,31的混乱值也为3。但是31,32,31,32,31的混乱值为5,这实在是太乱了。 Bsny想尽可能减少混乱值,但他有点累了,所以他决定最多取出k本书,再随意将它们放回到书架上。你能帮助

1335

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【JZOJ 4599】西行妖

Description 在幻想乡白玉楼有一棵终年不开花的樱树叫西行妖,西行寺幽幽子曾经为了让它开花而大量收集春度,然后被城管教训了一顿… 现在,幽幽子得到城管的允许,收集了S点春度,让西行妖重新开花。 西行妖可以被看成是一棵有n个节点的树,每个叶子节点被分配了1点春度就能开花(幽幽子不会无意义地使用她的春度,于是最多只会给同一个叶子节点分配1点春度),对于非叶子节点i,如果它有至少有1个儿子开花,

1140

【51NOD 1383】整数分解为2的幂

Description任何正整数都能分解成2的幂,给定整数N,求N的此类划分方法的数量!由于方案数量较大,输出Mod 1000000007的结果。 比如N = 7时,共有6种划分方法。7=1+1+1+1+1+1+1 =1+1+1+1+1+2 =1+1+1+2+2 =1+2+2+2 =1+1+1+4 =1+2+4Solution显然,当n为奇数时(除了1),fn=fn−

1031

【JZOJ 3861】【JSOI2014】支线剧情2

DescriptionSolution显然的树形DP, 设gxg_x表示以点x根,一次存档也没有,跑完所有子树的时间, 设fxf_x表示以x的子树全部跑完所需的时间,可以有存档,也可以没有,(包含从根走下来的时间) 有三种情况, 1. 当前点存档,子树没有存档, 2. 当前点存档,子树只有一个存档, 3. 当前点存档,子树有一个存档,其他的点想存档要从根走下来,情况1,3比较好做,先考虑

985

【JZOJ 3052】剪草

Description 有N棵小草,编号0至N-1。奶牛Bessie不喜欢小草,所以Bessie要用剪刀剪草,目标是使得这N棵小草的高度总和不超过H。在第0时刻,第i棵小草的高度是h[i],接下来的每个整数时刻,会依次发生如下三个步骤: 1. 每棵小草都长高了,第i棵小草长高的高度是grow[i]。 2. Bessie选择其中一棵小草并把它剪平,这棵小草高度变为0。注意:这棵小草并没有死掉,它

969

【51NOD 1048】【51NOD 1383】整数分解为2的幂 V2

Description任何正整数都能分解成2的幂,给定整数N,求N的此类划分方法的数量! 比如N = 7时,共有6种划分方法。7=1+1+1+1+1+1+1 =1+1+1+1+1+2 =1+1+1+2+2 =1+2+2+2 =1+1+1+4 =1+2+4Solution设gi,j,kg_{i,j,k}表示一个序列组成2i2^i这个数,这个序列中最大的数为2j2^j,最

912

【JZOJ 4685】礼物

Description 夏川的生日就要到了。作为夏川形式上的男朋友,季堂打算给夏川买一些生日礼物。 商店里一共有种礼物。夏川每得到一种礼物,就会获得相应喜悦值Wi(每种礼物的喜悦值不能重复获得)。 每次,店员会按照一定的概率Pi(或者不拿出礼物),将第i种礼物拿出来。季堂每次都会将店员拿出来的礼物买下来。 众所周知,白毛切开都是黑的。所以季堂希望最后夏川的喜悦值尽可能地高。 求夏川最后最大的喜

908

【Codeforces 678E】Another Sith Tournament &【JZOJ 4648】锦标赛

Description Codeforces The rules of Sith Tournament are well known to everyone. JZOJ 403机房最近决定举行一场锦标赛。锦标赛共有N个人参加,共进行N-1轮。 抽象题意:有n个人要两两对决(n-1)场,已知每两个人对决的胜率,求一安排顺序,使1的最大胜率,输出最大的胜率。 Solution 拿到题就可以得出此题肯定是状态压缩DP,而D

891

【JZOJ 4937】与运算

DescriptionSolution肯定先把所有的数转成二进制, 设一个gig_i表示i这个二进制被多少个数包含,也就是这个数前面可以放多少个数(满足aia_i and i=i), 这样就可以状态压缩DP了, 当前做到了i,枚举在i的基础上减掉一位转移到j,那么转移式为:fj=fi+j∗(gj−gi)f_j=f_i+j*(g_j-g_i)复杂度:O(mlog(m))O(m\log(m))Co

884

【JZOJ 4630】计数

Description 给出n和k,求出n位的k进制数中不包含两个连续的0的数,且没有前导 0的数有几个。如要求7位的十进制数,如1010230算一个,1000198和0011234 不算, Solution 普通DP: fi,0=fi−1,1 fi,1=m∗(fi−1,0+fi−1,1) 转化一下: fi=m∗(fi−1+fi−2) 套上高精度即可。 Code

878
上一篇: 【JZOJ 4813】running
下一篇: 【JZOJ 4807】破解
HOWARLI
博客等级 码龄11年 109粉丝 378原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值