如果自己是回文串可以做中心

如果一个串和另一个串的转置相等则可以凑一对

优先配对

#include <bits/stdc++.h>
using namespace std; int n,m,u[105];
string str[105];
vector <int> a,b; signed main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>str[i];
int ans=0;
for(int i=1;i<=n;i++) {
if(u[i]) continue;
for(int j=i+1;j<=n;j++) {
int flag=1;
for(int k=0;k<m;k++) if(str[i][k]!=str[j][m-k-1]) flag=0;
if(flag) {
u[i]=1;
u[j]=1;
a.push_back(i);
b.push_back(j);
ans+=2;
break;
}
}
}
int flag=0;
for(int i=1;i<=n;i++) {
int tmp=1;
for(int k=0;k<m;k++) if(str[i][k]!=str[i][m-k-1]) tmp=0;
if(tmp) flag=i;
}
if(flag) ++ans;
cout<<ans*m<<endl;
for(int i=0;i<a.size();i++) cout<<str[a[i]];
cout<<str[flag];
for(int i=b.size()-1;i>=0;--i) cout<<str[b[i]];
}

[CF1034B] Longest Palindrome - 贪心的更多相关文章

  1. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  2. 409. Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  3. LeetCode 409 Longest Palindrome

    Problem: Given a string which consists of lowercase or uppercase letters, find the length of the lon ...

  4. LeetCode Longest Palindrome

    原题链接在这里:https://leetcode.com/problems/longest-palindrome/ 题目: Given a string which consists of lower ...

  5. 每天一道LeetCode--409 .Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  6. 24. leetcode 409. Longest Palindrome

    409. Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the le ...

  7. [Swift]LeetCode409. 最长回文串 | Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  8. 【leetcode】409. Longest Palindrome

    problem 409. Longest Palindrome solution1: class Solution { public: int longestPalindrome(string s) ...

  9. [LeetCode&Python] Problem 409. Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

随机推荐

  1. python3-cookbook笔记:第十章 模块与包

    python3-cookbook中每个小节以问题.解决方案和讨论三个部分探讨了Python3在某类问题中的最优解决方式,或者说是探讨Python3本身的数据结构.函数.类等特性在某类问题上如何更好地使 ...

  2. 内网学习之Kerberos协议

    学习了解kerberos协议,有助于我们后期理解黄金票据和白银票据的原理 kerberos协议 kerberos是一种由麻省理工大学提出的一种网络身份验证协议.旨在通过使用密钥加密技术为客户端/服务器 ...

  3. Android.mk文件LOCAL_SDK_VERSION选项

    Api分类 internal api 翻译为内部API,理解为供sdk内部使用的API. 这类接口最初打算就是不对外公开的,有点private的意思. hide api 在源码中看到使用@hide 标 ...

  4. apue 外传

    先上目录 chapter 3 [apue] dup2的正确打开方式 chapter 10 [apue] 等待子进程的那些事儿 chapter 14 [apue] 使用文件记录锁无法实现父子进程交互执行 ...

  5. Jenkins集成jacoco收集单元测试覆盖率

    Jenkins集成jacoco收集单元测试覆盖率 2020-02-28 目录 0 整体思路1 Jenkins创建JacocoIntegrateTestDemo项目2 配置源码管理3 配置Build4 ...

  6. C#XML文件操作随笔

    以为公司一直没有电源屏厂家协议解析为DevVars相关的软件,手写费时费力还容易出错,用了2天时间做了一个.txt协议文件筛选加并解析成xml文件的工具,总结一下用到的几个知识点 1.LINQ 是一个 ...

  7. kaks calculator批量计算多个基因的选择压力kaks值

    欢迎来到"bio生物信息"的世界 今天给大家带来"批量计算kaks值"的技能. 关于kaks的背景知识我就不介绍了,感兴趣的自行搜索,这里直接开始讲怎么批量计算 ...

  8. 4~20MA 转 电压输出

    ICL7660  50mA LM2662/LM2663  200mA

  9. 安装TensorFlow失败

    ERROR: Could not find a version that satisfies the requirement tensorflow==2.1.0 (from versions: non ...

  10. HDU1862 - EXCEL排序

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1862 解题思路:结构体排序 #include <bits/stdc++.h> using ...