链接:https://ac.nowcoder.com/acm/contest/624/A
来源:牛客网

Ramen likes palindrome.

A palindrome is a word, number, phrase, or other sequences of characters which reads the same backward as forward, such as madam or racecar or the number 10801.

An all palindrome is such a string that each substring of it is a palindrome. For example, the string aaa is an all palindrome while aba is not.

There is a string, and Ramen wants to make it an all palindrome string. He has a magic skill that he can remove any character of the string as much as he wants. But cast such a spell will cost him a lot of energy. As a lazy boy, he wants to save energy to play games, so can you tell him the minimum number of the necessary characters that he needs to remove?

输入描述:

The input contains precisely two lines.The first line is an integer n(1 <= n <= 100000), which indicates the length of the given string.The second line is the given string S. It's guaranteed that S contains only lower case Lattin letters, i.e., a-z.

输出描述:

For each test case, output the minimum number of necessary removals.

示例1

输入

复制

22
welcometotheupcofhitwh

输出

复制

19

示例2

输入

复制

20
itstheeasiestproblem

输出

复制

16

示例3

输入

复制

25
goandgrabyoursignupreward

输出

复制

21

思路:炸一眼以为是回文串更改判断之后发现水体直接输出桶排最大的

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int book[100009];
int main()
{int n;string a;scanf("%d",&n);cin>>a;int max1 = 0;for(int i = 0; i < n;++i){book[a[i]-'a']++;if(book[a[i]-'a']>max1){max1 = book[a[i]-'a'];}}printf("%d\n",n-max1);return 0;
}

All Palindrome相关推荐

  1. 【LeetCode】Palindrome Partitioning 解题报告

    [题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...

  2. 234. Palindrome Linked List - Easy

    Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...

  3. LeetCode 125 Valid Palindrome(有效回文)(*)

    版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5062 ...

  4. Lintcode108 Palindrome Partitioning || solution 题解

    [题目描述] Given a strings, cutsinto some substrings such that every substring is a palindrome. Return t ...

  5. 数位DP 回文序列 POJ-3280 Cheapest Palindrome

    Cheapest Palindrome [ POJ - 3280 ] 题目大意: 给定字符串s,长度为m,由n个小写字母组成.在s的任意位置增删字母,把它变成回文串,增删特定字母的花费不同,求最小花费 ...

  6. Determine whether an integer is a palindrome. Do this without extra space.

    看到这个题目的时候,首先不认识 Determine这个单词.英文不好没办法,查了下是确认的意思,然后不懂 palindrome这个单词, 查了下是回文的意思. 问题是 回文是个什么东西,官方解释: A ...

  7. [leetcode] Palindrome Number

    2019独角兽企业重金招聘Python工程师标准>>> Determine whether an integer is a palindrome. Do this without e ...

  8. Uva - 12050 Palindrome Numbers【数论】

    题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...

  9. 【leetcode】132. Palindrome Partitioning II

    题目如下: 解题思路:本题是[leetcode]131. Palindrome Partitioning的升级版,要求的是求出最小cuts,如果用[leetcode]131. Palindrome P ...

  10. 409 Longest Palindrome

    Longest Palindrome 这题我完全想错了. 求最长回文.~~统计个个字母出现次数.奇数的保留最大的那个.偶数全保留.~~这个思路完全错了. 因为奇数中成对的数字也是可以拿来用的. 正确的 ...

最新文章

  1. Python -bs4反爬虫解决方法
  2. STL 之replace,replace_if,replace_copy,replace_copy_if
  3. how is service url defined in configuration.js consumed
  4. 综述:编程语言的发展趋势及未来方向
  5. android 版本更新工具类_报表分析工具FastReport .Net 2021年超大版本更新,实现了对.NET 5的支持...
  6. 解释型语言和编译型语言的区别_从泛型的使用情况看出你对语言的理解程度(2)...
  7. Python的数据类型与结构
  8. java备份mysql数据库备份_Java实现MySQL数据库备份
  9. 南开大学计算机考研2019分数线,2019年南开大学考研复试分数线已公布
  10. 小强的HTML5移动开发之路(27)—— JavaScript回顾2
  11. 数据结构笔记(十一)串
  12. yii php 弹窗,Yii框架弹出框功能示例
  13. 机器学习数学知识积累总结
  14. SpringMvc @PathVariable 工作原理
  15. kafka分布式消息系统集群搭建-- 详细过程
  16. 增选54位院士,京东副总裁梅涛等18位华人入选!
  17. 基于VRML的虚拟校园漫游系统
  18. Word文档docx的图标显示异常,doc的显示正常,但是可以用,解决办法
  19. Spring的Bean意义
  20. 做一次完美的数据迁移

热门文章

  1. Windows 批量创建用户
  2. FFT——傅里叶变换
  3. 【英语六级】【仔细阅读】(3)
  4. 在linux中,命令 nc -lk 和nc -lp 的区别是什么
  5. 【全链路追踪】全链路追踪介绍
  6. 计算机组成原理孙启良,[计算机硬件及网络]第1章 概论 计算机的基本组成.ppt
  7. 基于APS排程系统的物料管理有哪些优势?
  8. 【会议征稿|SPIE独立出版|往届已检索】第二届人工智能、虚拟现实与可视化国际学术会议(AIVRV 2022)
  9. QCC304x/QCC514x Pydbg在线调试
  10. 一篇读懂自动驾驶汽车决策层算法的新思路