绝对没坑

heyucheng 2023-06-24 10:31:04 2023-10-14 10:49:22 27 返回题目

#include<bits/stdc++.h>
using namespace std;
int n,m,a[1005],f[1010][3][40];
int dfs(int x,int loc,int cnt)
{
	if(x>n||cnt>m) return 0;
	if(f[x][loc][cnt]>0)
		return f[x][loc][cnt];
	if(a[x]==loc)
		return f[x][loc][cnt]=max(dfs(x+1,3-loc,cnt+1),dfs(x+1,loc,cnt))+1;
	else
		return f[x][loc][cnt]=max(dfs(x+1,3-loc,cnt+1),dfs(x+1,loc,cnt));
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	cout<<max(dfs(1,1,0),dfs(1,2,1));
	return 0;
}
{{ vote && vote.total.up }}