HBC14367String of CCPC题解

为你而来永不停止 算法基础篇 36 0
题库丰富多样,涵盖各个领域,全网最全C++题库,让您在练习中不断成长!
BaoBao has just found a stringsof lengthnconsisting of 'C' and 'P' in his pocket. As a big fan of the China Collegiate Programming Contest, BaoBao thinks a substringsisi+1si+2si+3 of sis "good", if and only if si=si+1=si+3='C' ,and si+2='P',where sidenotes the i-th character in string s. The value of sis the number of different "good" substrings in s. Two "good" substringssisi+1si+2si+3andsjsj+1sj+2sj+3are different ,if and onlyi≠j. To make this string more valuable, BaoBao decides to buy some characters from a character store. Each time he can buy one 'C' or one 'P' from the store, and insert the character into any position ins.But everything comes with a cost. If it's the i-th time for BaoBao to buy a character, he will have to spend i - 1units of value. The final value BaoBao obtains is the final value ofs minus the total cost of all the characters bought from the store. Please help BaoBao maximize the final value.

BaoBao has just found a string s of length n consisting of 'C' and 'P' in his pocket. As a big fan of the China Collegiate Programming Contest, BaoBao thinks a substring sisi+1si+2si+3 of s  is "good", if and only if si=si+1=si+3= 'C' ,and si+2='P', where si denotes the i-th character in string s. The value of s is the number of different "good" substrings in s. Two "good" substrings  sisi+1si+2si+3 and sjsj+1sj+2sj+3 are different ,if and only i ≠ j . To make this string more valuable, BaoBao decides to buy some characters from a character store. Each time he can buy one 'C' or one 'P' from the store, and insert the character into any position in s.But everything comes with a cost. If it's the i-th time for BaoBao to buy a character, he will have to spend i - 1 units of value. The final value BaoBao obtains is the final value of  s minus the total cost of all the characters bought from the store. Please help BaoBao maximize the final value.

HBC14367String of CCPC题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
想要在职场中立于不败之地?那就来试试全网最全C++题库,让您在练习中快速提升技能。

标签: HBC14367String of CCPC题解