Nikita and string

完整指南:从基础到高级使用 Semantic Kernel 通过本文的学习,你已经掌握了从基础到高级的使用方法。安装并配置。使用简单的文本生成和自然语言处理任务。利用任务链和工具扩展构建复杂的工作流。通过记忆管理上下文,创建更智能的应用。扩展多模态处理能力,集成图像和音频分析。将应用部署到云端,并通过 Azure Functions 提供智能服务。无论是构建简单的对话应用,还是创建多模态智能服务,都提供了强大的工具和灵活的扩展机制。希望这篇文章能帮助你更好地理解并运用这个框架,构建出更加智能和高效的应用。 阅读详情

One day Nikita found the string containing letters "a" and "b" only.

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

Input

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".

Output

Print a single integer — the maximum possible size of beautiful string Nikita can get.

Examples

Input

abba

Output

4

Input

bab

Output

2

Note

It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.

题意:

给出一个只有a,b且长度最长为5000的字符串。

能不能将这个字符串分成三部分,第一和第三部分只有a,第二部分由b组成,两部分皆可为空。

问你能不能分成这样的形式,如果能那么最长的长度是多少。

代码:

#include<stdio.h> 
#include<string.h>
#include<algorithm>
using namespace std;

char a[5001];
int b[5001], c[5001];

int main()
{
    while(~scanf("%s", a))
	{
	    memset(b, 0, sizeof b);
        memset(c, 0, sizeof c);
        
        int l = strlen(a); //长度 
        int sum = 0;
        
        for(int i = 0; i < l; i++)  //正着 
		{
            if(a[i] == 'b')  //第i个b前有几个a 
			    b[i] = sum;
            else 
			    sum++;
        }
 
        sum = 0;     //清空 
        for(int i = l-1; i >= 0; i--) //倒着 
		{
            if(a[i] == 'b') 
			   c[i] = sum;     
            else 
			   sum++;
        }

        int maxx = -0x3f3f3f3f;
        
        for(int i = 0; i < l; i++)
		{
            int s = 0;
            for(int j = i; j < l; j++)
			{
                if(a[j] == 'a') 
				   continue;
                s++;
                if(b[i]+s+c[j] > maxx)
				{
                    maxx = b[i]+s+c[j];
                }
            }
        }
        if(maxx == -0x3f3f3f3f) 
		    maxx = l;
        printf("%d\n", maxx);
    }
    return 0;
}

 

别再为多相机标定头疼了!用VisionMaster统一坐标系的保姆级教程 本文详细介绍了使用VisionMaster平台解决多相机视觉系统中坐标系统一问题的完整流程。从标定板选择到N点标定,再到实战演练,提供了从原理到落地的全方位指导,帮助工程师高效解决多相机定位引导中的坐标偏差问题。 阅读详情

相关推荐

java写一个多人线上聊天室

课程作业谔谔

weixin_51614848的博客 1136

Nikita and string 的题解

目录-0x01 题面题目描述输入格式输出格式题意翻译题目描述输入描述输出描述输入输出样例输入#1输出#1输入#2输出#20x00 思路0x01 定义状态0x02 状态转移方程0x03 注意细节!0x04 优化 -0x01 题面 题目描述 One day Nikita found the string containing letters “a” and “b” only. Nikita thinks that string is beautiful if it can be cut into 33 st

cqbzcky的博客 689

Apache Hop环境搭建实战:从零到一的下载、安装与配置指南

本文详细介绍了Apache Hop环境搭建的全过程,包括下载、安装与配置指南。从选择正确的JDK17版本到设置关键环境变量,再到启动GUI界面和解决常见问题,提供了全面的实战指导。适合数据工程师和ETL开发者快速上手这一强大的数据集成工具。

weixin_42634811的博客 574

Nikita and string (暴力)

One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters,...

自渡的博客 506

vue引入使用腾讯地图

// 引入鹅厂地图 initMap(lat = 0.0000000, lng = 0.0000000) { // 定义地图中心点坐标- var center = new TMap.LatLng(lat, lng) // 定义map变量,调用 TMap.Map() 构造函数创建地图 map = new TMap.Map(document.getElementById('txMapBox'), { center: center, // 设.

LiangRZ 4536

【Codeforces Round #442 (Div. 2)】 B. Nikita and string (线性状态dp)

线性dp入门题, 也可以枚举区间来做。题意:一个5000的字符串,只有a,b两个字符,现在可以可以删一下字符,使得剩下的字符可以裁剪成三段,第一段和第三段只含a,第二段只含b。问删除后的字符串最长可以是多长。

hmc0411的博客 1696

Unity技能系统核心:从理论到实践构建可扩展的Buff管理器

本文深入探讨了Unity游戏开发中构建可扩展技能系统的核心——Buff管理器。通过剖析三层架构(数据、逻辑、渲染)与独立组件管理模式,提供了从Buff数据定义、管理器核心实现到可视化编辑器搭建的完整实践方案,旨在解决技能系统维护难题,提升开发效率与代码质量。

weixin_29002209的博客 253

B. Nikita and string

One day Nikita found the string containing letters “a” and “b” only.Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, wh

wtml 519

2026.3.10:最新claude code完美解决方案,跳过登录界面,使用国内deepseek-v4-pro进行计费

本文介绍了一种绕过Claude登录界面直接使用国内DeepSeek-V4-Pro服务的解决方案。通过npm全局安装@anthropic-ai/claude-code包,并配置5个关键环境变量:API认证令牌、基础URL(指向DeepSeek服务)、指定模型为deepseek-v4-pro、禁用非必要流量等。文中提供了4张配图辅助说明配置过程,但未展示具体内容。该方案可实现直接计费使用,无需通过官方登录流程。

拥抱具身智能,昇腾Ascend C 6506

ROS机器人未知环境自主探索功能包explore_lite最全源码详细解析(五)

本系列文章主要针对ROS机器人常使用的未知环境自主探索功能包explore_lite展开全源码的详细解析,并进行概括总结。 本系列文章共包含六篇文章,前五篇文章主要介绍explore_lite功能包中 explore.cpp、costmap_tools.h、frontier_search.cpp、costmap_client.cpp等源码实现文件中全部函数的详细介绍,第六篇文章进行概括总结,包含自主探索功能包explore_lite的简介,实现未知环境自主探索功能的原理及流程总结,效果演示,使用功能包exp

慕羽★的博客 1510

ACM刷题之codeforce————Nikita and string

Nikita and stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Nikita found the string containing letters "a" and "b" only.Nikita thinks...

小时的枫的博客 485

2025实战|C#上位机+STM32实现LED串灯控制:串口通信+PWM调光+自定义帧协议(附上下位机源码)

粘包:一次收到“BRIGHT:50LED_OFF”,解析完全错乱;乱码:串口波特率/编码不匹配,指令变成“??H??50”;丢帧:数据传输中少字符,比如“BRIGHT:5”,解析出亮度5而非50。因此我们设计字节级自定义帧协议协议先行:无论简单还是复杂场景,先定义清晰的帧协议,避免数据错乱;串口稳字当头:下位机用环形缓冲区接收,上位机加锁发送,避免丢包/粘包;跨线程必处理:C#上位机所有UI更新必须用Invoke,否则必崩溃;硬件是基础:接线、供电、共地这些细节,比代码更易出问题;

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 755

CF 877B Nikita and string

B. Nikita and string time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output One day Nikita found the string containing letters “a” and “b” only. Niki...

Cruiying的博客 209

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

怀旧版电脑GBC模拟器

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

CodeForces 877 B Nikita and string

B. Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Nikita found the string containing letters "a" and "...

swqeaaa的博客 322

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

E - Nikita and string 暴力 + 前缀和

传送门 题意:给你一个字符串,问你能否将它们按照第一部分为a,第二部分为b,第三部分为a 化成三个部份。其中这三个部分可以为空,也就是说单独的aaa,bbb都可以。 思路:我们可以做一下a的前缀和 和 后缀和, 然后再O(n^2)枚举b的区间,不断维护一个最大值。 /** * From: * Qingdao Agricultural University * Created by Xiangwa...

weixin_43960370的博客 380

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

CodeForces - 877B Nikita and string

Nikita and string One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without...

weixin_30838873的博客 228

Nikita and string [思维-暴力] ACM

codeforcesNikita and string time limit per test 2 seconds memory limit per test 256 megabytes One day Nikita found the string containing letters "a" and "b" only. Nikita thinks...

weixin_30472035的博客 114

CF877B Nikita and string TJ

文章目录前言的前言前言更新题意简述题解CodeCodeCode关于滚动数组 前言的前言 本 TJ 同步发布于洛谷,在线求赞(bushi 前言 蒟蒻第一篇题解,在线求审核大大给过 awa。 如果此题解有什么问题的话欢迎各位大巨佬提出。 题目链接:CF877B 题目类型:dp,一讲就会,一做就废(;′⌒`)。 更新 2021/5/31:因为帮同学调代码添加了新发现的滚动数组问题。 题意简述 给定一个只含有 “a” 和 “b” 的字符串,求这个字符串中最长的子序列,子序列满足以下条件之一: 全为 “a”。

cqbzljt的博客 192

Codeforces 877 B. Nikita and string (技巧)

Description One day Nikita found the string containing letters “a” and “b” only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the orde

小坏蛋_千千 942

Codeforces 877 B Nikita and string

题目地址 题意:给你一个字符串让你删除一些字符,使得可以分割成3个字符串,第一,三个全是a,第二个全是b,这个删完的字符串最长多少? 思路:我们遍历字符串,如果当前字符为a,那我们可以构成a或aba,如果是b的话,那就是可以构成ab的,然后每次遍历之后我们要转移,因为我们发现当前是a的我们可以继续构成a或者ab,ab的我们可以构成aba或者ab,所以我们对于ab就取ab和a的较大者aba就取ab或者aba的较大者

不要錯過才珍惜 882

CodeForces - 877B Nikita and string 【枚举区间】

B. Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Nikita found the string contai

哇-WA 的博客 504

字符串dp codeforces B - Nikita and string

就是看在不更改各字母顺序的情况下,可以组成形如(a),(a+b),(a+b+a)的字符串的最长长度,其实就是子串拼成的a+b+a子串的最长长度 拿3个数组记录从s[0]到s[j]的符合条件的最长长度,这三个数组分别表示“a”,"ab"/"ba","aba"三种字符串 "a":只要记录字符串中“a”的个数就好了,每次遇到“a”dp[0][j]++; "ab":是由“a”或者“ab”

wwwlps的博客 266
上一篇: 二叉搜索树【 HDU - 3791 】
下一篇: Trees on the level【 HDU - 1622 】
Daisy's一乐景三
博客等级 码龄8年 2粉丝 56原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值