hdu2146

来源:互联网 发布:淘宝联盟分享了没9有钱 编辑:程序博客网 时间:2024/06/05 17:00
/*
分析:
    hash。
    字典树TLE,各种优化无果= =III。。。函数调用真的
很消耗时间额。。。不过给的字符串全是01串、且长度不
超过60个,这是不是和64位整形有点儿像呀,所以。。。
方法呼之欲出了吧 →_→ 。
    刚开始968MS险过。。就这样搁那儿不是咱风格~,优化
之~,453MS。

                                        2013-04-21
*/





#include"iostream"#include"cstdio"#include"cstring"#include"algorithm"using namespace std;int n,L,K,tot;__int64 hash[60*1011];int main(){int i,l;int limit;__int64 temp,base;char str[66];while(scanf("%d%d%d",&n,&L,&K)!=-1){tot=0;limit=L-K;base=((__int64)1<<(K-1))-1;for(i=0;i<n;i++){scanf("%s",str);temp=0;for(l=0;l<K;l++)temp=(temp<<1)+str[l]-'0';hash[tot++]=temp;for(l=1;l<=limit;l++){temp=((temp&base)<<1)+str[l+K-1]-'0';hash[tot++]=temp;}}sort(hash,hash+tot);int ans,cnt,pre;cnt=ans=0;pre=-11;hash[tot]=-1;for(i=0;i<=tot;i++){if(hash[i]!=pre){if(cnt>ans)ans=cnt;cnt=1;pre=hash[i];}elsecnt++;}cout<<ans<<endl;}return 0;}


原创粉丝点击