#include <cstdio> #include <string.h> int casenum; char Shang [1009]; // first array. The default is the array length, as sideways put array // int shanglenght; char xia [1009]; // second array, an array of short default, as a longitudinal array of the discharge // int xialenght; Short Tab [1002 ] [1002]; // record data, from the beginning, because 0 is used to consider a case where an empty array int Dongtai () { Memset (Tab, 0, the sizeof (Tab)); / * = shanglenght the sizeof ( Shang); the printf ( "% D \ n-", shanglenght); xialenght = the sizeof (xia); the printf ( "% D \ n-", xialenght); * / int congdingrow = 0; int congdingcel = 0; int I, J ; for (I = 0; xia [I] = '\ 0';! I ++) // the array, the array of short for (j = 0; shang [ j] = '\ 0';! ++ j) {// the number of the head of the array, within the circulation congdingrow = i + 1; congdingcel = J +. 1; Tab [congdingrow] [congdingcel] = Tab [-congdingrow. 1] [congdingcel] + 1'd; // first with a row update if (tab [congdingrow] [congdingcel ]> tab [congdingrow] [congdingcel-1 ]); // then compare numbers on the left, because I probably the else { Tab [congdingrow] [congdingcel] = Tab [congdingrow] [-congdingcel. 1]; } } the else { congdingrow = I + . 1; congdingcel = j +. 1; Tab [congdingrow] [congdingcel] = Tab [congdingrow] [-congdingcel. 1]; // current number of characters i and j the current character on the array are not equal when there is a character array, and j j not on the same array, the array is not the optimal value j is tab [congdingrow] [congdingcel-1 ] // current number of characters i and j the current character is not equal to the array when the array is not i is the same, it can be appreciated i was not on the array is the same // in both cases, the value is not the same! // And there is a situation that is in front of me and a successful match plus 1, after the match on the back do not you want to compare more than just say no equivalent on an array of J IF (the Tab [congdingrow-1] [congdingcel] > Tab [congdingrow] [congdingcel]) Tab [congdingrow] [congdingcel] = Tab [congdingrow-. 1] [congdingcel]; } * / int congdingrow = I +. 1; int congdingcel = J +. 1; IF (xia [I] Shang == [J]) { Tab [congdingrow] [congdingcel] = Tab [-congdingrow. 1] [-congdingcel. 1] + 1'd; } / * for (int. 1 = K; K <= I; K ++) { } the else { tab[congdingrow][congdingcel]=tab[congdingrow-1][congdingcel]>tab[congdingrow][congdingcel-1]?tab[congdingrow-1][congdingcel]:tab[congdingrow][congdingcel-1]; } for(int op=1;op<=j;++op){ printf("%d ",tab[k][op]); } puts(""); }*/ return tab[i][j]; return 1; } int main (){ scanf("%d",&casenum); for(int i=1;i<=casenum;++i){ scanf("%s",shang); scanf("%s",xia); // printf("%s\n",shang); // printf("%s\n",xia); printf("%d\n",Dongtai ()); } }
zuichang_gonggong_zixvlie
Guess you like
Origin www.cnblogs.com/waibizi/p/12070160.html
Ranking