Train of thought

The four-dimensional dp. Let f[I][j][k][0/1]f[I][j][k][0/1]f[I][j][J][I][j][K][0/1] be the height of the third point JJJ, belonging to the KKK hump (including the ascending segment and the descending segment, the peak belongs to the ascending segment and the valley belongs to the descending segment), 000 stands for being located in the ascending segment. 111 means in the descending section.

Obviously, the state transition equation is zero


f [ i ] [ j ] [ k ] [ 0 ] = r = j + 1 4 f [ i 1 ] [ r ] [ k ] [ 0 ] + f [ i 1 ] [ r ] [ k ] [ 1 ] f [ i ] [ j ] [ k ] [ 1 ] = r = 1 j 1 f [ i 1 ] [ r ] [ k ] [ 1 ] + f [ i 1 ] [ r ] [ k 1 ] [ 0 ] f[i][j][k][0]=\sum\limits_{r=j+1}^4f[i-1][r][k][0]+f[i-1][r][k][1]\\ f[i][j][k][1]=\sum\limits_{r=1}^{j-1}f[i-1][r][k][1]+f[i-1][r][k-1][0]

When the boundary is set to I =2i=2i=2, assign to each height.

code

#include<bits/stdc++.h>
#definerep(i,st,ed) for(int i=st; i<=ed; ++i)
#definebl(u,i) for(int i=head[u]; i; i=e[i].nxt)
#define en puts("")
#define LLM LONG_LONG_MAX
#define LLm LONG_LONG_MIN
#define pii pair<ll,ll> 
typedef long long ll;
typedef double db;
using namespace std;
const ll INF=0x3f3f3f3f;
void read(a) {}
void OP(a) {}
void op(a) {}
template <typename T, typename. T2>inline void read(T &_, T2 &... oth)
{
    int__ =0; _ =0;
    char ch=getchar(a);while(!isdigit(ch))
    {
        if(ch==The '-') __ =1;
        ch=getchar(a); }while(isdigit(ch))
    {
        _=_*10+ch- 48;
        ch=getchar(a); } _ = __? - _ : _;read(oth...) ; }template <typename T>
void Out(T _)
{
    if(_ <0)
    {
        putchar(The '-'); _ = - _; }if(_ > =10)
       Out(_ /10);
    putchar(_ %10+'0');
}
template <typename T, typename. T2>inline void OP(T _, T2... oth)
{
	Out(_).putchar('\n');
	OP(oth...) ; }template <typename T, typename. T2>inline void op(T _, T2... oth)
{
	Out(_).putchar(' ');
	op(oth...) ; }/ * # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # * /
const ll N=11;
ll n,t,ans;
ll f[N<<1] [6][N][2];
int main(a)
{
	read(n,t);
	f[2] [2] [1] [1] =1;
	f[2] [3] [1] [1] =2;
	f[2] [4] [1] [1] =3;
	rep(i,3,n)
	{
		rep(k,1,t)
		{
			rep(j,1.4)
			{
				rep(r,j+1.4)
					f[i][j][k][0]+=f[i- 1][r][k][0]+f[i- 1][r][k][1];
				rep(r,1,j- 1)
					f[i][j][k][1]+=f[i- 1][r][k][1]+f[i- 1][r][k- 1] [0];
			}
		}
	}
	ll ans=0;
	rep(i,1.4)
		ans+=f[n][i][t][0];
	op(ans);
}
Copy the code