#include <iostream> using namespace std; int v[1001][31]; int main() { int T, W; scanf("%d%d", &T, &W); for(int t = 1; t <= T; ++t) { int temp; scanf("%d", &temp); //状态转移方程: 前t分钟移动w次可抓到的最大苹果数v[t][w] for(int w = 0; w <= W && w <= t; ++w) if(temp==1 && w%2==0 || temp==2 && w%2==1) //若t-1分钟时移动w步在1树,而temp==1,或者 //若t-1分钟时移动w步在2树,而temp==2时 v[t][w] = v[t-1][w] + 1; else if(w-1>=0) //若t-1分钟时移动w步在2树,而temp==1,或者 //若t-1分钟时移动w步在1树,而temp==2时, //分为移动与不移动两种情形: v[t][w] = max(v[t-1][w-1]+1, v[t-1][w]); else //else v[t][w] = v[t-1][w]; } printf("%d/n", v[T][W]); return 0; }