有个人在2柯树之间来回,在1~T 的时刻i 时,其中一颗棵树会掉一个果子,规定只能掉头m 次,问最多能获得多少果子
f[ i ][ j]
#include <iostream> #include <algorithm> #include <cstring> using namespace std ; #define N 1003 int n,m,a[N],f[N][40][3]; void solve(){ cin>>n>>m; int j,x; for(int i=1;i<=n;i++) cin>>a[i]; for (int i = 1; i <= n; i++) { int t = a[i]; for (int j = m; j >= 0; j--) { f[i][j][t] = max(f[i - 1][j][t], f[i - 1][j + 1][3 - t]) + 1; f[i][j][3 - t] = f[i - 1][j][3 - t]; } } int res = 0; for (int i = 0; i <= m; i++) { res = max(res, max(f[n][i][2], f[n][i][1])); } cout<<res; } signed main(){ solve(); }
标签:Apple,int,Catching,POJ,2385,include From: https://www.cnblogs.com/towboa/p/17206854.html