noi 9268 酒鬼
题目链接:http://noi.openjudge.cn/ch0206/9268/
题意:有N瓶酒,不能连续喝>=3瓶的酒,问能喝的最大的酒量。
f[i][j] 前 I 瓶中连续喝了 j 瓶的最大酒量
f[i][0] = f[i-1][3];
f[i][1,2] = f[i-1][j-1] + a[i];
#include <bits/stdc++.h> using namespace std; int a[710]; int f[710][4]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { f[i][0] = f[i-1][3]; int maxx = f[i][0]; for(int j=1;j<=2;j++) { f[i][j] = f[i-1][j-1] + a[i]; maxx = max(maxx,f[i][j]); } f[i][3] = maxx; } printf("%d\n",f[n][3]); return 0; }