绝对没坑*3

liujunhao 2024-03-02 16:00:23 2024-03-02 16:01:05 7 返回题目

#include<bits/stdc++.h>

using namespace std;

int T,w;

int a[1010];

int mem[110][3][10];

int dfs(int t,int loc,int cnt){

if(t>T)return 0;
if(mem[t][loc][cnt]!=-1)return mem[t][loc][cnt];
int c=0;
if(a[t]==loc)c=1;else c=0;
int tmp=dfs(t+1,loc,cnt);
if(cnt+1<=w){
	tmp=max(tmp,dfs(t+1,3-loc,cnt+1));
}
return mem[t][loc][cnt]=tmp+c;

} int main(){

memset(mem,-1,sizeof(mem));
cin>>T>>w;
for(int i=1;i<=T;i++)cin>>a[i];
cout<<max(dfs(1,1,0),dfs(1,2,1));
return 0;

}

{{ vote && vote.total.up }}