|NOIOJ|动态规划|9268:酒鬼

http://noi.openjudge.cn/ch0206/9268/ 

思路同核电站一题,只是这里不是求方案数,一样的

#include
#include
#include
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
int a[705];
int f[705][5];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i=1;i<=n;i++) scanf("%d", &a[i]);
    ms(f,0);
    for (int i=1;i<=n;i++)
    for (int j=0;j<3;j++)
    {
        if (j==0)
        {
           f[i][j] = max(f[i][j], max(f[i-1][0], max(f[i-1][1], f[i-1][2])));
        } else f[i][j] = max(f[i][j], f[i-1][j-1]+a[i]);
    }
    int ans = 0;
    for (int i=0;i<3;i++) ans = max(ans, f[n][i]);
    printf("%d\n", ans);
    return 0;
}


你可能感兴趣的:(OpenJudge,Noi,动态规划)