题解:UVA13257 License Plates
Chenxuhang_play · · 题解
题目大意
在字符串
思路
暴力肯定是过不了的,考虑使用其他方法。
可以发现在
桶
桶
桶
将上述桶放至循环内,可以大幅度优化时间复杂度,单组数据的时间复杂度约为
整体程序的时间复杂度为
关键代码
for(int i=0;i<s.size();i++)
{
if(!a[s[i]-'A'])
{
a[s[i]-'A'] = 1;
for(int j=i+1;j<s.size();j++)
{
if (!b[s[i]-'A'][s[j]-'A'])
{
b[s[i]-'A'][s[j]-'A']=1;
for(int k=j+1;k<s.size();k ++)
{
if(!c[s[i]-'A'][s[j]-'A'][s[k]-'A'])
{
c[s[i]-'A'][s[j]-'A'][s[k]-'A']=1;
ans++;
}
}
}
}
}
cout<<ans<<endl;
}