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

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

优先配对

#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. Android布局管理器-使用TableLayout表格布局管理器实现简单的用户登录页面

    场景 Android布局管理器-使用FrameLayout帧布局管理器显示层叠的正方形以及前景照片: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article ...

  2. SpringBoot支持SpringData es

    ElasticSearch CRUD 1.springboot springData es spring data 是spring对数据访问抽象.这些数据可以放入db,index,nosql等包含以下 ...

  3. Oracle12c传统数据库模式 OGG

    OGG12C 配置 环境配置: 安装数据库Oracle12c 安装源端OGG:oggs  PORT:7809 安装目标端OGG:oggt   PORT:7909 源端和目标端地址:127.0.0.1 ...

  4. PTA 凑零钱(深度优先搜索)

    韩梅梅喜欢满宇宙到处逛街.现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债.韩梅梅手边有 10000 枚来自各个星球的硬币,需要请你帮她盘算 ...

  5. Selenium实战(五)——HTML测试报告

    一.概览下载与安装 HTMLTestRunner是unittest的一个扩展,可以生成易于使用的HTML测试报告.HTMLTestRunner是在BSD许可证下发布的. 下载地址:http://tun ...

  6. 从接口自动化测试框架设计到开发(二)操作json文件、重构json工具类

    用例模板里的请求数据多,看起来很乱,所以可以通过访问另外一个文件的方式获取请求数据 把请求数据都放在一个json文件中 取出login的内容: import json fp = open('G:/un ...

  7. [POI2004]PRZ [枚举子集]

    怎么全是 模拟退火 啊,这明明是个 枚举子集 的板子题. 考虑 \(n \leq 16\) 二进制没错了.. \(dt_i\) 表示 \(i\) 这个状态下 \(\max{t_j}\),\([\tex ...

  8. xctf进阶-unserialize3反序列化

    一道反序列化题: 打开后给出了一个php类,我们可以控制code值: `unserialize()` 会检查是否存在一个 `__wakeup()` 方法.如果存在,则会先调用 `__wakeup` 方 ...

  9. 技术之心 | 云信和TA们携手打响防疫战

      1月27日,教育部发布<关于2020年春季学期延期开学的通知>,各地高等院校.中小学.幼儿园纷纷推迟开学.疫情当前,学生们的鼠年寒假变得无比漫长. 网易云信众多教育客户以行动践行教育的 ...

  10. 让bat文件自动以管理员身份运行

    · 让bat文件自动以管理员身份运行 如何让bat文件自动以管理员身份运行,将这段写在bat文件的前头即可 : %1 mshta vbscript:CreateObject("Shell.A ...