#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int dp[maxn], n;
vector<string> s;
bool rhyme(const string& a, const string& b)
{
int u = (int)a.size() - 1, v = (int)b.size() - 1;
int cont = 0;
while(a[u] == b[v] and u >= 0 and v >= 0)
{
cont++, u--, v--;
}
if(cont >= max((int)a.size(), (int)b.size()) - 1) return true;
return false;
}
int solve(int i, int j)
{
if(dp[i] != -1) return dp[i];
if(i == n) return 0;
int caso1;
if(i == j)
{
caso1 = solve(i + 1, i + 1);
}
else
caso1 = solve(i + 1, j);
int caso2;
if(rhyme(s[i],s[j]))
{
caso2 = solve(i + 1, i) + 1;
}
else
caso2 = 0;
return dp[i] = max(caso1, caso2);
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
cin >> n;
for(int i = 0; i < n; i++)
{
string a;
cin >> a;
s.push_back(a);
}
ans = 0;
sort(a.begin(), a.end());
do
{
memset(dp, -1, sizeof(dp));
ans = max(ans, solve(0, 0));
} next_permutation(a.begin(), a.end());
}
Compilation message
rima.cpp: In function 'int main()':
rima.cpp:65:2: error: 'ans' was not declared in this scope
ans = 0;
^~~
rima.cpp:65:2: note: suggested alternative: 'abs'
ans = 0;
^~~
abs
rima.cpp:67:7: error: 'a' was not declared in this scope
sort(a.begin(), a.end());
^
rima.cpp:74:4: error: expected 'while' before 'next_permutation'
} next_permutation(a.begin(), a.end());
^~~~~~~~~~~~~~~~
rima.cpp:74:4: error: expected '(' before 'next_permutation'
rima.cpp:74:40: error: expected ')' before ';' token
} next_permutation(a.begin(), a.end());
^