本文主要是介绍hdu 5504 GT and sequence(dp),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:hdu 5504 GT and sequence
代码
#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;
typedef long long ll;
const int maxn = 100;int N;
ll x, dp[maxn][2];int main () {int cas;scanf("%d", &cas);while (cas--) {scanf("%d", &N);dp[0][0] = dp[0][1] = 1;for (int i = 1; i <= N; i++) {scanf("%lld", &x);dp[i][0] = dp[i][1] = x;for (int j = 0; j < i; j++) {dp[i][0] = min(dp[i][0], min(dp[j][0] * x, dp[j][1] * x));dp[i][1] = max(dp[i][1], max(dp[j][0] * x, dp[j][1] * x));}}ll ans = dp[1][1];for (int i = 2; i <= N; i++)ans = max(ans, dp[i][1]);printf("%lld\n", ans);}return 0;
}
这篇关于hdu 5504 GT and sequence(dp)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!