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

#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. 我的18vps~

    自从买了18vps的香港虚拟主机后,就面临一个问题,浏览器无法访问它的apache服务,后来发现,需要同时开启nginx服务: /usr/local/nginx/sbin/nginx -c /usr/ ...

  2. C:产生随机数

    函数说明 #include <time.h> time_t time(time_t *t); 功能:获取当前系统时间 参数:常设置为NULL 返回值:当前系统时间, time_t 相当于l ...

  3. mybatis 源码分析--日志分析

    1. MyBatis 没有提供日志实现,需要接入第三方的日志组件,但是第三方的日志组件都各自的Log级别,而不相同 实现方式:适配器模式   Slf4jImpl 2. 自动扫描日志实现,并且第三方日志 ...

  4. spring+mybatis报Cannot load JDBC driver

    今天做用maven搭建ssm框架的例子,在测试的时候一直报ava.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver 这个异常,找 ...

  5. 2.1.FastDFS-单机拆分版-调度器安装配置

    Centos610系列配置 我们在Centos610FastDFS单机模式-FastDFS安装 中已经完成了FastDFS的安装,接下来我们进行FastDFS调度器的安装. 1.找到FastDFS配置 ...

  6. Centos610安装Nexus

    1.下载Nexus 地址:     https://pan.baidu.com/s/1D5AI6zmuRBSMK0k7j41VuQ 提取码: q50j 选择02-nexus 2.新建nexus账号 u ...

  7. Spring Boot中Restful Api的异常统一处理

    我们在用Spring Boot去向前端提供Restful Api接口时,经常会遇到接口处理异常的情况,产生异常的可能原因是参数错误,空指针异常,SQL执行错误等等. 当发生这些异常时,Spring B ...

  8. 无法打开物理文件 XXX.mdf",操作系统错误 5.5(拒绝访问) 的解决办法

    用T-SQL命令附加数据库时,出现如下异常信息: 无法打开物理文件 XXX.mdf".操作系统错误 5:"5(拒绝访问.)". (Microsoft SQL Server ...

  9. sql 中u.*什么意思

    i.*  i是一个表的别名,i.*是这个表的所有列,比如 select i.* from customer i; 相当于 select id,name,password from customer;

  10. list中的对象或者map中的版本号排序 version排序

    经常会用到版本号排序,直接把他封装成一个工具用起来比较方便. List<A> aList = new ArrayList<>(); ...aList 赋值 ... Collec ...