起起落落
題解:畫一下圖我們就可以發現要求的序列是波浪並且整體下降趨勢的。
因此我們考慮表示以結尾的並且滿足要求的子序列個數。那麼就有轉移:對於前面的數字,如果滿足的都可以作爲要求子序列的中間點,而如果碰到的,假設我們已經枚舉到了個可以作爲中點的點,那麼當前可以作爲子序列的開始點和這箇中點組合。同時以結尾的子序列新加上作爲終點也可以和這個箇中點組合。因此轉移方程就是
代碼
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long dp[2010], a[2010];
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
#endif
//k 2k - 1 2k 2k + 1
//1 1 2 3
//2 3 4 5
//3 5 6 7
//4 7 8 9
int n;
cin >> n;
long long ans = 0;
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
for(int i = 2; i < n; ++i) {
int k = 0;
for(int j = i - 1; j >= 0; --j) {
if(a[j] < a[i]) {
k++;
}else if(a[j] > a[i]){
dp[i] = (dp[i] + (dp[j] + 1) * k) % mod;
}
}
ans = (dp[i] + ans) % mod;
}
cout << ans << endl;
return 0;
}