#include <iostream>
using namespace std;
//求数组最长递增元素个数。
int addadd(int a[],int n)
{
if (n <= 0)return 0;
int i = 0;
int count = 0;
int max = 1;
int *b = new int[n];
for (; i < n; i++)
{
b[i] = 1;
count = 1;
for (int j = 0; j < i; j++)
{
if (a[i]>a[j])
{
if (b[j] + 1>b[i])
{
b[i] = b[j] + 1;
count = b[i];
if (count > max)
{
max = count;
}
}
}
}
}
return max;
}
int main()
{
int a[] = {1,2,3,4,5,6};
cout<<addadd(a,sizeof(a)/sizeof(int))<<endl;
return 0;
}
#include <iostream>
using namespace std;
//求数组中最大连续乘积。
//暴力轮询法。
int Grial(int a[],int n)
{
int max = a[0];
for (int i = 0; i < n; i++)
{
int count = 1;
for (int j = i; j >= 0; j--)
{
count *= a[j];
if (count>max)
{
max = count;
}
}
}
cout << max << endl;
return max;
}
int main()
{
int a[] = { -2,1,-2,23,0};
Grial(a, sizeof(a) / sizeof(int));
}
算法题:最大递增数组个数
最新推荐文章于 2021-09-20 16:09:09 发布