SRM330 div1 medium
#include <algorithm> #include <string> #include <vector> typedef long long LL; using namespace std; class PrefixFreeSubsets { public: LL cantPrefFreeSubsets(vector <string> words) { int n=words.size(); LL ans[60]; ans[n]=1; sort(words.begin(),words.end()); for(int i=n-1;0<=i;i--) { int j=i+1; while(j<n && words[i].size()<=words[j].size() && words[i]==words[j].substr(0,words[i].size())) j++; ans[i]=ans[i+1]+ans[j]; } return ans[0]; } };