https://www.lydsy.com/JudgeOnline/problem.php?id=3384
A problem of DP
not too difficult
You should DP the information of
the time, the position and the number of step
Code of AC:
#include<bits/stdc++.h>
using namespace std;
int DP[1010][40][10];
int A[1010];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i){
cin>>A[i];
}
for(int i=1;i<=n;++i){
DP[i][0][1]=DP[i-1][0][1]+(A[i]==1);
DP[i][0][2]=DP[i-1][0][2]+(A[i]==2);
for(int j=1;j<=m;++j){
DP[i][j][1]=max(DP[i-1][j][1]+(A[i]==1),DP[i-1][j-1][2]+(A[i]==1));
DP[i][j][2]=max(DP[i-1][j][2]+(A[i]==2),DP[i-1][j-1][1]+(A[i]==2));
}
}
cout<<max(DP[n][m][1],DP[n][m][2])<<endl;
}