#include <iostream>
#include <string.h>
#include <cstdio>
using namespace std;
const int size = 5100;
int maxlen[size];//记录当前第1个点到第i个点之间的最长下降序列长度
int maxnum[size];//记录1~i之间的最长下降序列个数
int main()
{
int a[size];
int n;
while (scanf("%d", &n) != EOF){
for (int i = 1; i <= n; i ++){
scanf("%d", &a[i]);
maxnum[i] = 0;
maxlen[i] = 1;
}
for (int i = 1 ; i <= n; i ++){
for (int j = 1; j < i; j ++){
if (a[i] < a[j]){
maxlen[i] = max(maxlen[i], maxlen[j]+1);
}
}
}
for (int i = 1; i <= n; i ++)
if (maxlen[i] == 1)maxnum[i] = 1;
for (int i = 2; i <= n; i ++){
int sum = 0;
bool check = false;
for (int j = i-1; j > 0; j --){
if (a[j] > a[i]){
if (maxlen[j]+1 == maxlen[i]){
maxnum[i] += maxnum[j];
}
}
if (a[j] == a[i]){
if (maxlen[i] == 1)maxnum[i] = 0;//如果搜索到一个相同的数后仍没有找到符合要求的序列,则为了避免重复赋值为0
break;
}
}
}
int maxx = -1;
for (int i = 1; i <= n; i ++){
if (maxlen[i] > maxx) maxx = maxlen[i];
}
int ans = 0;
for (int i = 1; i <= n; i ++){
if (maxlen[i] == maxx) ans += maxnum[i] ;
}
printf("%d %d\n", maxx, ans);
}
return 0;
}
USACO 4.3.1 Buy Low, Buy Lower
最新推荐文章于 2022-08-05 16:04:13 发布