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 |
DP能错吗?怎么总是TLE啊?到底用什么算法#include<stdio.h> #include<string.h> char a[501],b[501]; int c[501][501]; int main() { int i,j,na,nb; while(scanf("%s%s",a,b)!=EOF) { na=strlen(a);nb=strlen(b); for(i=0;i<=na;i++)c[i][0]=0; for(j=0;j<=nb;j++)c[0][j]=0; for(i=1;i<=na;i++) for(j=1;j<=nb;j++) { if(a[i-1]==b[j-1])c[i][j]=c[i-1][j-1]+1; else if(c[i][j-1]>c[i-1][j]) c[i][j]=c[i][j-1]; else c[i][j]=c[i-1][j]; } printf("%d\n",c[na][nb]); }while(1); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator