跳到正文

题解

'\n' || solution - AT_joi2013ho2

littlebug约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年3月31日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 2 分钟
获赞
2

版本

  1. v1当前

省流:太久没做远古 AT 题忘记加 '\n' 导致的。

Solution

显然的 dp,设 fi,j,0/1f_{i,j,0/1} 为只考虑 s1∼sis_1 \sim s_i,t1∼tjt_1 \sim t_j,最后一位选 O 或 I 的答案,于是有转移:

fi,j,x=max⁡{fi−1,j,!xsi=xfi,j−1,!xtj=xf_{i,j,x} = \max \begin{cases} f_{i-1,j,!x} & s_i = x \\ f_{i,j-1,!x} & t_j = x \end{cases}

然后注意判一下 i,j=0i,j=0 和首位是否为 I 即可。

Code

C++
int n,m,qwq[N],f[N][N][2];
string s,t;

signed main()
{
	read(n,m),read(s,t),s="$"+s,t="$"+t;
	
	int ans=0;
	rep(i,0,n) rep(j,0,m)
	{
		s[i]=='O' ? chmax(f[i][j][0],i && f[i-1][j][1] ? f[i-1][j][1]+1 : -inf) : chmax(f[i][j][1],i ? f[i-1][j][0]+1 : -inf);
		t[j]=='O' ? chmax(f[i][j][0],j && f[i][j-1][1] ? f[i][j-1][1]+1 : -inf) : chmax(f[i][j][1],j ? f[i][j-1][0]+1 : -inf);
		chmax(ans,f[i][j][1]);
	}
	
	write(ans,'\n'); // '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' '\n' /fn
	
	return 0;
}

华风夏韵,洛水天依!

原文