Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么总是tle阿,暴力阿,为什么阿,代码贴上#include <stdio.h> #include <string.h> int value[27]={0}; char s[100002][11]; int main(){ int i,j,k,m,n,len,p,v,max,flag; char temp; scanf("%d",&n); j=0; for(i=0;i<n;i++){ scanf("%s",s[j++]); if(strlen(s[j])>10) j--; } n=j; scanf("%d",&m); for(i=0;i<m;i++){ scanf("%d",&p); for(j=0;j<27;j++) value[j]=-200; for(j=0;j<p;j++){ getchar(); scanf("%c %d",&temp,&v); value[temp-'a']=v; } max=0; for(j=0;j<n;j++) { len=strlen(s[j]); if(len>p) continue; v=0; flag=0; for(k=0;k<len;k++) { if(value[s[j][k]-'a']==-200) { flag=1; break; } v+=value[s[j][k]-'a']; } if(flag==1) continue; if(max<v) max=v; } printf("%d\n",max); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator