题目:https://odzkskevi.qnssl.com/f291a3cd7af74cfc9f9770e2dde91718?v=1532124336
思路:
其实我不太清楚为什么我dp没过。。
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
int n;
int tot=1;
while(scanf("%d",&n)!=EOF)
{
int a[20];
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
long long int ans=-INF;
long long int p;
for(int i=0;i<n;i++)
{
p=1;
for(int j=i;j<n;j++)
{
p=p*a[j];
ans=max(ans,p);
}
}
if(ans>=0)printf("Case #%d: The maximum product is %lld.\n",tot++,ans);
else printf("Case #%d: The maximum product is 0.\n",tot++);
cout<<endl;
}
return 0;
}
本文探讨了一个关于寻找数组中具有最大乘积的连续子序列的问题,并提供了一种使用动态规划方法解决该问题的代码实现。代码通过遍历数组并不断更新累积乘积来寻找最优解。
418

被折叠的 条评论
为什么被折叠?



