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 0ms , 230k#include<iostream> using namespace std; int len_1 , len_2 ; char str_1[1010] , str_2[1010]; int dp( int a , int b ) { if( a==-1 && b==-1 ) return 0; else if( a==-1 ) return b+1; else if( b==-1 ) return a+1; if( str_1[a]==str_2[b] ){ return dp( a-1 , b-1 ); } else{ int x = dp( a-1 , b ) + 1, y = dp( a , b-1 ) + 1, z = dp( a-1 , b-1 ) + 1; return min ( min( x, y ) , z ); } } int main() { while( ~scanf("%d%s%d%s" , &len_1 , str_1 , &len_2 , str_2 ) ) cout<<dp( len_1-1 , len_2-1 )<<endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator