日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 202A】LLPS (思维,字符串)

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 202A】LLPS (思维,字符串) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.

You are given string?s?consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.

We'll call a non-empty string?s[p1p2...?pk]?=?sp1sp2...?spk?(1??≤??p1?<?p2?<?...?<?pk??≤?|s|) a?subsequence?of string?s?=?s1s2...?s|s|, where?|s|?is the length of string?s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".

String?x?=?x1x2...?x|x|?is?lexicographically larger?than string?y?=?y1y2...?y|y|?if either?|x|?>?|y|?and?x1?=?y1,?x2?=?y2, ...,?x|y|?=?y|y|, or there exists such number?r?(r?<?|x|,?r?<?|y|) that?x1?=?y1,?x2?=?y2, ...,?xr?=?yr?and?xr??+??1?>?yr??+??1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".

String?s?=?s1s2...?s|s|?is a?palindrome?if it matches string?rev(s)?=?s|s|s|s|?-?1...?s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

Input

The only input line contains a non-empty string?s?consisting of lowercase English letters only. Its length does not exceed?10.

Output

Print the lexicographically largest palindromic subsequence of string?s.

Examples

Input

radar

Output

rr

Input

bowwowwow

Output

wwwww

Input

codeforces

Output

s

Input

mississipp

Output

ssss

Note

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

題目大意:

? ?給你一個字符串,讓你找到字典序最大的回文子序列。(給出了字典序的定義和子序列的定義)

解題報告:

? ?因為數據量是10,本來想寫搜索,但是看了眼樣例,發現一個小規律,答案都是相同的字符,那么結論就出來了,,,找到ASCII最大的那個字符,輸出個數就可以了。

? 證明可以用樣例,,,你就算是選了一些比較大的回文串比如abzcczba,那么完全可以用其中最大的那個字符z來打頭。于是我們證明了一定用最大的那個字符打頭,那么我們假設字符串zaaz,那么完全可以直接取zz,于是得出結論。。

AC代碼:

#include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; //string s[5000],str; //int len; //int top; //bool fit(string ss) { // int l = ss.length(); // if(l == 0) return 0; // for(int i = 0; i<l/2; i++) { // if(ss[i] != ss[l-i]) return 0 ; // } // return 1; //} //void dfs(int cur,string tmp) { // if(cur >= len) return ; // if(fit(tmp)) s[++top] = tmp; // dfs(cur+1,tmp+str[cur+1]); // dfs(cur+1,tmp); //} int main() {string str;cin>>str;int len = str.length(); // string w = string(1,str[0]); // dfs(0,w); // printf("%d\n",top); // for(int i = 1; i<=top; i++) { // cout << s[i] << endl; // }char cur = 0;for(int i = 0; i<len; i++) {if(str[i] > cur) cur = str[i];}int cnt = 0;for(int i = 0; i<len; i++) {if(str[i] == cur) cnt++;}for(int i = 1; i<=cnt; i++) {putchar(cur);}return 0 ;}

(話說代碼里那個搜索不太對好像,,,也沒debug)

總結

以上是生活随笔為你收集整理的【CodeForces - 202A】LLPS (思维,字符串)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。