题意:给长度为N的字符串,只存在小写字母。问你山形的子序列有多少种,这里是子序列不是子串。所谓的山形就是严格的递增到递减。
思路:从左到右求每一个位置递增子序列的个数,然后再从右向左求每一个位置递增子序列的个数,然后对应位置相乘就可以得到最终结果。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
using namespace std;
int n;
const int maxn=100010;
char s[maxn];
int dp[maxn];//dp[i]是以第i个字母结尾的递增子序列的个数(子序列的长度>=2)
int has[27];//has[i]是以字母'a'+i结尾的递增子序列的个数(子序列的长