Maximum Product UVA

来源:互联网 发布:多管升级数据 编辑:程序博客网 时间:2024/06/09 15:47

问题类型:暴力枚举

问题链接
03pie’s solution for [UVA-11059]:

#include<bits/stdc++.h>//包含所有头文件using namespace std;typedef long long LL;const double PI=acos(-1.0);const int maxn=18+2;int a[maxn];int main(){//    freopen("F://inp.txt","r",stdin);    int n,kase=0;    while(~scanf("%d",&n)){        LL max=0;        for(int i=0;i<n;i++)    scanf("%d",&a[i]);        for(int i=0;i<n;i++){            LL tmp=a[i];            for(int j=i+1;j<n;j++){                if(tmp>max) max=tmp;                tmp=tmp*a[j];   //              if(tmp>max) max=tmp;            }            if(tmp>max) max=tmp;        }        printf("Case #%d: The maximum product is %lld.\n\n",++kase,max);    }       return 0;}
0 0