学到了一种统计方案数的方法。
\(f[i] = \sum\limits_{dp_i = dp_j + 1且price_j>price_i}{f[j]}\)
(sigma怎么写......)
剩下就是一个最下降升子序列。
#include<bits/stdc++.h>
using namespace std;
long long price[6000];
long long dp[6000],dp2[6000];
long long n;
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> price[i];
dp[i] = 1;
}
for(int i = 2; i <= n; i++){
long long maxn = 0;
for(int j = 1; j < i; j++){
if(price[j] > price[i])
dp[i] = max(dp[i],dp[j] + 1);
}
}
for(int i = 1; i <= n; i++){
if(dp[i] == 1) dp2[i] = 1;
for(int j = 1; j < i; j++){
if(dp[i] == dp[j] + 1 && price[i] < price[j]) dp2[i] += dp2[j];
else if(dp[i] == dp[j] && price[i] == price[j]) dp2[i] = 0;
}
}
long long ans1 = 0,ans2 = 0;
for(int i = 1; i <= n; i++)
if(ans1 < dp[i]) ans1 = dp[i];
for(int i = 1; i <= n; i++)
if(dp[i] == ans1) ans2 += dp2[i];
cout << ans1 << " " << ans2 << endl;
return 0;
}