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,开心,哈哈#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int a[500][500]; char str1[500],str2[500]; int main() { while(scanf("%s%s",str1,str2)!=EOF) { int len1=strlen(str1); int len2=strlen(str2); for(int i=0;i<=len1;i++) for(int j=0;j<=len2;j++) a[i][j]=0; for(int i=0;i<len1;i++){ for(int j=0;j<len2;j++){ if(str1[i]==str2[j]) a[i+1][j+1]=a[i][j]+1; else a[i+1][j+1]=max(a[i][j+1],a[i+1][j]); } } printf("%d\n",a[len1][len2]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator