我的代码
#include <bits/stdc++.h>
using namespace std;
int t, w, tmp, mem[1005][35][2];
bool ids[1005];
int DFS(int m, int move, bool side)
{
if(m == t) return 0;
if(move == w + 1) return -1;
if(mem[m][move][side] != -1) return mem[m][move][side];
if(ids[m] == side)
{
mem[m][move][side] = DFS(m + 1, move, side) + 1;
return mem[m][move][side];
}
mem[m][move][side] = max(DFS(m + 1, move + 1, !side) + 1, DFS(m + 1, move, side));
return mem[m][move][side];
}
int main()
{
fill(mem[0][0], mem[0][0] + 70350, -1);
cin >> t >> w;
for(int x = 0; x < t; x++)
{
cin >> tmp;
ids[x] = tmp - 1;
}
cout << DFS(0, 0, 0);
return 0;
}
#4WA没过 正确答案118 程序输出119 求助大佬