192B Walking in the Rain

简单DP,设 f[i] 为到达第 i 个位置最迟的天数,那么 f[i] 为 min(f[i-2], a[i]) 和 min(f[i-1], a[i]) 中的较大者;

# include <cstdio>

# include <algorithm>



# define N 1005



using namespace std;



int n, a[N];

int f[N];



void init(void)

{

    scanf("%d", &n);

    for (int i = 1; i <= n; ++i)

        scanf("%d", &a[i]);

}



void solve(void)

{

    f[1] = a[1], f[2] = min(f[1], a[2]);

    for (int i = 3; i <= n; ++i)

    {

        f[i] = max(min(f[i-2], a[i]), min(f[i-1], a[i]));

    }

    printf("%d\n", f[n]);

}



int main()

{

    init();

    solve();



    return 0;

}

你可能感兴趣的:(in)