Bzoj

Sol

简单\(DP\)

# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1005);
const int Zsy(19650827);

IL ll Input(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int n, a[_], f[2][_][_];

IL void Up(RG int &x, RG int y){
	x += y;
	if(x >= Zsy) x -= Zsy;
}

int main(RG int argc, RG char* argv[]){
	n = Input();
	for(RG int i = 1; i <= n; ++i) a[i] = Input(), f[0][i][i] = 1;
	for(RG int i = 1; i < n; ++i)
		for(RG int l = 1; l + i <= n; ++l){
			RG int r = l + i;
			if(a[l] < a[l + 1]) Up(f[0][l][r], f[0][l + 1][r]);
			if(a[l] < a[r]) Up(f[0][l][r], f[1][l + 1][r]);
			if(a[r - 1] < a[r]) Up(f[1][l][r], f[1][l][r - 1]);
			if(a[l] < a[r]) Up(f[1][l][r], f[0][l][r - 1]);
		}
	printf("%d\n", (f[0][1][n] + f[1][1][n]) % Zsy);
	return 0;
}

相关文章:

  • 2022-01-19
  • 2021-12-16
  • 2022-02-17
  • 2022-01-23
  • 2021-06-16
  • 2021-10-26
  • 2022-12-23
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2021-08-02
  • 2021-07-04
  • 2022-01-23
  • 2021-05-27
相关资源
相似解决方案