Submission #100166

#TimeUsernameProblemLanguageResultExecution timeMemory
100166pamajRima (COCI17_rima)C++14
14 / 140
100 ms36892 KiB
#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)

rima.cpp: In function 'bool rhyme(const string&, const string&)':
rima.cpp:19:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(cont >= max(a.size(), b.size()) - 1) return true;
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...