Topic Portal
1 /*2 Lis Template title: The title is wrong, is to find the longest ascending sub-sequence of words! 3 programming Good tired:)4 */5#include <cstdio>6#include <iostream>7#include <cstring>8#include <algorithm>9#include <string>Ten using namespacestd; One A Const intMAXN = 1e2 +Ten; - Const intMAXM = -; - Const intINF =0x3f3f3f3f; the CharS1[MAXM][MAXN], S2[MAXM][MAXN]; - intDP[MAXN][MAXN]; - intRT[MAXN][MAXN]; - intFlag; + - voidPrintintXinty) + { A if(!x &&!y)return ; at - if(Rt[x][y] = =0) - { -Print (X-1, Y1); - if(!flag) {printf ("%s", s1[x-1]); Flag =1;} - Elseprintf ("%s", s1[x-1]); in } - Else if(Rt[x][y] = =1) Print (X-1, y); to ElsePrint (x, y1); + } - the voidLIS (intLen1,intlen2) * { $Memset (DP,0,sizeof(DP));Panax Notoginsengmemset (RT,0,sizeof(RT)); - for(intI=0; i<=len1; ++i) rt[i][0] =1; the for(intI=0; i<=len2; ++i) rt[0][i] =-1; + A for(intI=1; i<=len1; ++i) the { + for(intj=1; j<=len2; ++j) - { $ if(!STRCMP (s1[i-1], s2[j-1])) $ { -DP[I][J] = dp[i-1][j-1] +1; -RT[I][J] =0; the } - Else if(dp[i-1][J] >= dp[i][j-1])Wuyi { theDP[I][J] = dp[i-1][j]; -RT[I][J] =1; Wu } - Else About { $DP[I][J] = dp[i][j-1]; -RT[I][J] =-1; - } - } A } + theFlag =0; -Print (len1, len2); Puts (""); $ } the the intMainvoid)//POJ 2250 Compromise the { the //freopen ("poj_2250.in", "R", stdin); - in while(SCANF ("%s", s1[0]) ==1) the { the intLen1 =1, Len2 =1; About while(strcmp (s1[len1-1],"#")) scanf ("%s", &s1[len1++]); theLEN1-=1; scanf ("%s", s2[0]); the while(strcmp (s2[len2-1],"#")) scanf ("%s", &s2[len2++]); the + LIS (Len1, len2); - } the Bayi return 0; the } the - /* - Die Einkommen der abgeordneten muessen dringend verbessert werden the */
LIS POJ 2250 Compromise