codeforces 583 D - Once Again...

codeforce 583D Once Again... - 最长上升子序列 /** codeforce 583D Once Again... 给定一个数列包含n个数,将它复制t次,得到一个新的数列, 求这个数列的最长非递减子序列。 看到题目条件n比较小t比较大,而子序列又要求是非递减的,也就是说当t大于n的某一个倍数时, 中间一段子序列应该是全部相同的一个数。 思考一下便可以发现,以n段作为分解来考虑,预处理出前n段以某个数字结尾的最长非递减 子序列用inc[i]表示 阅读详情

题目链接

希哥哥推荐的好题。

当k小于100,直接构造出来,然后直接求数组;当k大于100时,构造出 n 个原串,求其最长上升子序列,然后加上(k-n)*原串中出现次数最多的数的出现次数,即为答案。

再推荐一篇博客:https://blog.youkuaiyun.com/yjt9299/article/details/82966703

#include<bits/stdc++.h>
#define mem(a,b) memset((a),b,sizeof(a))
typedef long long ll;
const int N=100010;
using namespace std;
int a[10010],b[110],dp[10010];
int main()
{
    mem(a,0);
    mem(b,0);
    mem(dp,0);
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        b[i]=0;
        for(int j=1;j<=n;j++)
            if(a[i]==a[j])
                b[i]++;
    }
    int maxx=0;
    for(int i=1;i<=n;i++)
        maxx=max(maxx,b[i]);
    int cnt;
    if(k<=100)
    {
        cnt=n+1;
        for(int i=2;i<=k;i++)
        {
            for(int j=1;j<=n;j++)   
                a[cnt++]=a[j];
            //开始写错了,写成这样:a[cnt++]=a[(cnt-1)%n];
        }
        int ans=0;
        for(int i=1;i<=n*k;i++)
        {
            dp[i]=1;
            for(int j=1;j<i;j++)
            {
                if(a[i]>=a[j])
                    dp[i]=max(dp[i],dp[j]+1);
            }
            ans=max(ans,dp[i]);
        }
        printf("%d",ans);
        return 0;
    }
    cnt=n+1;
    for(int i=2;i<=n;i++)
        for(int j=1;j<=n;j++)
            a[cnt++]=a[j];
    ll ans=0;
    for(int i=1;i<=n*n;i++)
    {
        dp[i]=1;
        for(int j=1;j<i;j++)
        {
            if(a[i]>=a[j])
                dp[i]=max(dp[i],dp[j]+1);
        }
        ans=max(ans,(ll)dp[i]);
    }
    ans+=(k-n)*maxx;
    printf("%I64d",ans);
    return 0;
}

 

【SAM2系列】windows单GPU复现时的bug解决记录 windows运行sam2,就感觉在开一艘破破烂烂的船,每走一步报一个错,bug源源不断的冒出来😭😭😭😭😭。 阅读详情

相关推荐

银河麒麟V10SP1系统盘瘦身指南:如何制作一个只含必需软件的轻量级安装镜像

本文详细介绍了银河麒麟V10SP1系统盘瘦身的完整流程,从依赖分析到最小化镜像构建,帮助用户创建只含必需软件的轻量级安装镜像。通过智能包筛选、KickStart定制和性能优化,显著减少ISO体积和部署时间,适用于服务器批量部署等场景。

weixin_26765287的博客 404

codeforces 583D. Once Again...

D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of positive integers a1, a2, ..., an × T o...

yjt9299的博客 361

Jetson Orin NX 单目标跟踪算法实战

本文对比了NanoTrack和MixFormerV2两种目标跟踪算法在Jetson Orin NX边缘设备上的实际表现。通过天空小目标跟踪场景测试发现,NanoTrack虽然表征能力较弱,但具有目标身份一致性强、失败模式可控、计算负担小等优势,更适合作为边缘端默认算法。MixFormerV2则适用于高速运动等特定场景。实验数据显示NanoTrack在Orin NX上可达200FPS,远高于MixFormerV2的38-120FPS。建议先采用NanoTrack构建稳定系统,后续再评估复杂算法的适用性。

karmueo46的博客 625

CodeForces 582 B.Once Again...(LIS)

Description 给出一长度为len的序列和一整数t,构成一长度为len*t的序列满足a[i]=a[i-len](len &lt; i &lt;=len*t),要求输出这个长串的最长非严格上升子序列长度 Input 第一行为两个整数len和t,第二行len个整数ai表示这个序列(1&lt;=len&lt;=100,1&lt;=t&lt;=10^7,1&lt;=ai&lt;=300) ...

ZSQ 665

【从零开始学Skynet】实战篇《球球大作战》(一):功能设计

为了能把之前在基础篇中学习到的Skynet的各种知识结合起来,所以在实战篇中,我们准备开发一个完整的游戏案例《球球大作战》,介绍分布式游戏服务端的实现方法。

我是一条寻水的鱼 2978

BitLocker恢复密钥丢失?从原理到实战的完整解锁与系统重生指南

磁盘加密技术是数据安全的核心防线,它通过对存储设备上的数据进行编码,确保未经授权的用户无法访问。其原理主要基于加密算法(如AES)与密钥管理机制,在操作系统启动前或数据读写时进行实时加解密。这项技术的核心价值在于防止设备丢失或被盗后的数据泄露,尤其对于笔记本电脑和移动设备至关重要。典型的应用场景包括企业办公电脑、存有敏感信息的个人设备以及符合合规性要求的行业。当使用Windows系统自带的BitLocker加密功能时,若因硬件改动、系统更新等触发保护机制,用户可能会面临需要输入恢复密钥才能启动的困境。本文聚

weixin_34006965的博客 489

Codeforces 582B Once Again... 【LIS变形】

题目链接:Codeforces 582B Once Again… B. Once Again… time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given an array of positive intege

世界很大 875

vins-fusion环境配置、安装与测试

本文主要介绍如何搭建vins-fusion的运行环境,以及解决vins-fusion编译运行时遇到的环境冲突问题,并在此基础上实现例程的运行。

qq_52068373的博客 1万+

Codeforces Round #323 D Once Again...

题意:给你n和T,n表示n个数,T表示将这n个数复制T次、 问:复制了T次之后新生成的n*T个数的最长不下降子序列的长度为多少? 思路:首先考虑一个问题,如果复制了T次之后,这T次中间的很多次是不是选择的是n个数中出现最多的某个数? 答案是,一定是。 那么,接下来还有一个问题就是,我很有可能将这n个数复制了很多次之后这些数可以组成一个新的最长不上升子序列、  首先,我们算出将n个数中出现次数

m494428831的博客 503

LangGraph 中 Human-in-the-loop

摘要:本文探讨了在自主AI Agent系统中实现"人工介入关键节点"(HIL)的技术方案,主要基于LangGraph框架构建。针对Agent可能执行高风险操作(如删除数据库)的问题,提出通过断点机制在关键节点暂停流程,实现人工审批后再继续执行。具体实现包括:(1)使用checkpointer组件持久化状态;(2)通过interrupt_before/after参数设置断点;(3)支持三种交互模式:批准、编辑和输入。文章还提供了代码示例,展示如何在不同场景(如工具调用)中动态触发人工审核机

qq_52053775的博客 153

Airtest进阶使用篇-提高脚本稳定性+批量运行脚本

Airtest进阶篇,主要分享如何提高脚本稳定性+如何批量运行脚本生成测试报告!

程序员小杨哥的博客 2569

Codeforces 582 B Once Again... (LIS)

Codeforces 582 B Once Again... (LIS)

追梦赤子心 1215

Ardupilot飞控姿态角与姿态角速度控制过程分析(超长篇)

目录 目录 摘要 1.代码控制过程分析 摘要 本节主要记录自己学习ardupilot飞控代码的姿态角速度的控制过程 1.代码控制过程分析 可以看出:AC_AttitudeControl *attitude_control; //指针对象 virtual void rate_controller_run() = 0;是AC_AttitudeContro...

陌城烟雨 1万+

CodeForces - 583D Once Again... LIS 循环

题意:给你n个数(n<=100,ai<=300) 一个T,求n重复T次的最长非递减子序列。 题解:我直接考虑4 3 2 1 的例子,当其重复4次时会出现1 2 3 4 的子序列 ,此时再怎么重复,这也是最长的递增序列,无非是多出(T-n)个1.   所以直接不完全(不会证明地)归纳处一个答案:ans=T>n?(T-n)*M+lis(a,n*n):lis(a,n*T...

aeiv52006的博客 112

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

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

【17.07%】【codeforces 583D】Once Again...

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given an array of positive integers a1, a2, …, an × T of length n × T...

236

廖雪峰Python教程[完整版]

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

Codeforces 583D. Once Again... (LIS变形)

题目链接:http://codeforces.com/contest/583/problem/D 给你t个长度为n的数组。问你最长不下降子序列的长度。 一开始用第一个n数组的lis和最后一个n数组的lis和中间最多相同的数字出现的个数相加。这是错的,比如5 6 3 4 1 2 可以发现数组的长度很小,有一个循环节,最多是n吧。所以t <= n只要暴力求解。大于的话,再加上数字出现的最...

weixin_30318645的博客 134

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

codeforces 583 D. Once Again... (LIS + 贪心)

D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of positive integers

whai的专栏 687

codeforces 583B B. Once Again...(LIS)

题解 : 我们要注意到一个东西就是说一个序列复制 n 遍一定到 lis 最后一个要么是最大的元素,要么是这个序列中重复最多的元素,这样的话,我们对于 t < n 的情况直接暴力求 lis 就可以,对于 t > n 的情况,我们先复制n遍,再把剩下的出现最多的元素加入到这个序列中去就可以了.#include <iostream> #include <algorithm> #include <cstri

Glory 的 博客 324

Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS

D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of positive intege...

weixin_30929195的博客 105

[codeforces 582b]Once Again…

给一串数列,周期延拓T次,求最长不降子序列长度。 可以大胆猜想这个数列由上升,重复某个数,再上升构成(可以证明),设序列长度为n,先求出延拓n次后的数列的各个位置的最长不降子序列,然后找延拓T次的最大值。 #include #include #include using namespace std; int dp1[10010]={0},dp2[10010]={0},dp3[310]={0}

MaticsL的专栏 1411

codeforces 583B B. Once Again...(dp)

题目链接:codeforces 583B题目大意:给出一个序列,是由一个长度为n的序列复制T次得到的,问最长子序列的长度。题目分析: 我们可以暴力的做n*n内的部分,得到这部分的最长不降子序列。 我们可以知道如果通过选取递减的可以得到更好的结果,那么在这之中一定已经选过,就算每次下降都能得到更好的结果,那么n次下降也能保证后面添加的全部都是只加入相同的元素,所以我们找到出现次数最多的元素,然后加入这

llin-黎辰 2180

Codeforces 582B Once Again...

You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of

XDU_PYL的博客 610

Codeforces 582B Once Again... LIS变形

Codeforces 582B Once Again... LIS变形

淘萄桃的博客 690

CodeForces 424D Biathlon Track【二维dp】

Description Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoro

MissZhou要努力 797
上一篇: HDU 6386 SPFA变形
下一篇: 矩阵快速幂求斐波那契模板
flyzer
博客等级 码龄9年 27粉丝 146原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值