Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stack>
- #include <algorithm>
- //#include <bits/stdc++.h>
- using namespace std;
- vector<string>s;
- int n;
- bool compare_two_strings(string A, string B) {
- vector<int> cntA(26, 0);
- vector<int> cntB(26, 0);
- for(int i = 0; i < A.size(); i++) {
- cntA[A[i] - 'A']++;
- }
- for(int i = 0; i < B.size(); i++) {
- cntB[B[i] - 'A']++;
- }
- for(int i = 0; i < 26; i++) {
- if(cntA[i] > cntB[i]) {
- return false;
- }
- }
- return true;
- }
- int dinamicko(int i){
- if(i==n){
- return 0;
- }
- int result=0;
- int k=s[i].size();
- for(int j=0; j<s.size(); j++){
- if(k+1==s[j].size()){
- if(compare_two_strings(s[i], s[j])==true){
- result=max(result, dinamicko(j) + 1);
- }
- }
- }
- return result;
- }
- int main()
- {
- cin>>n;
- for(char A='A'; A<='Z'; A++){
- string A1=" ";
- A1+=A;
- s.push_back(A1);
- }
- for(int i=0; i<n; i++){
- string a;
- cin>>a;
- sort(a.begin(), a.end());
- s.push_back(a);
- }
- sort(s.begin(), s.end());
- int result = 0;
- for(int i = 0; i < 26; i++) {
- result = max(result, dinamicko(i) + 1);
- }
- cout << result + 1<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement