# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100166 | pamaj | Rima (COCI17_rima) | C++14 | 100 ms | 36892 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |