# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100166 | pamaj | Rima (COCI17_rima) | C++14 | 100 ms | 36892 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 18;
int dp[1 << maxn], n;
vector<string> s;
bool rhyme(const string& a, const string& b)
{
int u = a.size() - 1, v = b.size() - 1;
int cont = 0;
while(a[u] == b[v] and u >= 0 and v >= 0)
{
cont++, u--, v--;
}
if(cont >= max(a.size(), b.size()) - 1) return true;
return false;
}
int solve(int i, int mask)
{
if(dp[mask] != -1) return dp[mask];
int ans = 0;
for(int j = i + 1; j < n; j++)
{
if(i == -1)
{
ans = max(ans, solve(j, mask | (1 << j)) + 1);
}
else if(rhyme(s[i], s[j]))
{
ans = max(ans, solve(j, mask | (1 << j)) + 1);
}
}
return dp[mask] = ans;
}
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);
}
memset(dp, -1, sizeof(dp));
cout << solve(-1, 0) << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |