|
|
back to boardgood idea to avoid mistake I have some mistake in the staion name which I can't find it in my code. Then I search all the string my write and calculate LCS. The string has maximal LCS is what we want to find. Like that: int __(string ss){ if(f.find(ss)==f.end()){ int ans=0,pos=0; rep(ki,1,cnt){ mst(dp,0); for(int i=1;i<=ss.length();i++){ for(int j=1;j<=s[ki].length();j++){ if(ss[i-1]==s[ki][j-1])dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } if(dp[ss.length()][s[ki].length()]>ans)ans=dp[ss.length()][s[ki].length()],pos=ki; } return pos; } return f[ss]; } Then I got AC from wa2 Edited by author 08.10.2021 04:46 |
|
|