根据数据范围,暴力可以解决,对每一个串,找与其互为回文的串,或者判断自身是否为回文串,然后两两将互为回文的串排列在头尾,中间放且只能最多放一个自身为回文串的串,因为题目说每个串都是不同的

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; string str[];
int cache[], self[], s[], chosen[]; void run_case() {
int n, m;
cin >> n >> m;
for(int i = ; i <= n; ++i)
cin >> str[i];
for(int i = ; i <= n; ++i) {
bool flag = true;
for(int j = ; j < m/ && flag; ++j) {
if(str[i][j] != str[i][m-j-]) flag = false;
}
if(flag) {
self[i] = ;
continue;
}
if(cache[i]) continue;
string now = str[i];
reverse(now.begin(), now.end());
for(int j = ; j <= n; ++j) {
if(j != i && now == str[j]) {
cache[i] = j; break;
}
}
}
vector<int> ans, selfs;
int top = ;
for(int i = ; i <= n; ++i)
if(cache[i] && !chosen[i]) {
ans.push_back(i);
s[++top] = cache[i];
chosen[cache[i]] = i;
} else if(self[i]) selfs.push_back(i);
if(selfs.size()) ans.push_back(selfs[]);
while(top) {
ans.push_back(s[top--]);
}
cout << ans.size() * m << "\n";
for(auto i : ans)
cout << str[i];
} int main() {
ios::sync_with_stdio(false), cin.tie();
//cout.setf(ios_base::showpoint);cout.precision(10);
//int t; cin >> t;
//while(t--)
run_case();
cout.flush();
return ;
}

Codeforces 1304B. Longest Palindrome的更多相关文章

  1. Codeforces Round #620 (Div. 2) B. Longest Palindrome

    Returning back to problem solving, Gildong is now studying about palindromes. He learned that a pali ...

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

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

  3. 409. Longest Palindrome

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

  4. LeetCode 409 Longest Palindrome

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

  5. LeetCode Longest Palindrome

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

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

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

  7. 24. leetcode 409. Longest Palindrome

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

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

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

  9. 【leetcode】409. Longest Palindrome

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

随机推荐

  1. radhat 6.7修改mac地址方法

    vi ifcfg-eth0 #HW……,即注释掉原硬件地址. 再自己照着原地址写:MACADDR="新mac地址" 重启

  2. js遍历传参给html

    <p id="subp" hidden><button id= "upsub"shiro:hasPermission="sys:me ...

  3. RT_THREAD之组件学习

    CmBacktrace (Cortex Microcontroller Backtrace)是一款针对 ARM Cortex-M 系列 MCU 的错误代码自动追踪.定位,错误原因自动分析的开源库.支持 ...

  4. mysql之mysql的安装

    此次MySQL安装的版本为:MySQL8.0 系统为:centos6.9 64位 一.利用yum仓库安装 wget https://repo.mysql.com//mysql80-community- ...

  5. hadoop学习笔记(一):NameNade持久化和DataNode概念

    其中的fsimage 称为时点备份,又叫磁盘镜像快照,这个是NameNode的一个 持久化的方式之一:缺点,在内存数据序列化的时候比较慢 具体的过程:因为我们所知道的NameNode一般是存储在内存中 ...

  6. eclipse配置tomcat后修改server.xml文件(如编码等)无效问题

    我们用eclipse配置好tomcat后,在处理中文乱码或是配置数据源时,我们要修改Tomcat下的server.xml等文件. 修改后重启Tomcat服务器时发现xml文件又被还原了. 因为Tomc ...

  7. ASP.NET Core搭建多层网站架构【3-xUnit单元测试之简单方法测试】

    2020/01/28, ASP.NET Core 3.1, VS2019, xUnit 2.4.0 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[3-xUnit单元测试 ...

  8. leetCode练题——38. Count and Say

    1.题目 38. Count and Say The count-and-say sequence is the sequence of integers with the first five te ...

  9. 「JSOI2013」游戏中的学问

    「JSOI2013」游戏中的学问 传送门 考虑 \(\text{DP}\) 设 \(dp_{i, j}\) 表示将前 \(i\) 个人分成 \(j\) 个集合,并且第 \(i\) 个人在第 \(j\) ...

  10. ParameterizedType 使用方法

    ParameterizedType 它是jdk提供的参数化类型,包括了如下 请求参数,和响应参数都是 参数话类型.记住凡是含有<T>中的都是参数话类型. public static < ...