D e s c r i p t i o n Description Description
有 n n n个数要入栈然后出栈,但这个栈只能容纳 m m m个数,求出栈顺序数,对4096取模
n , m ≤ 2000 n,m\leq 2000 n,m≤2000
S o l u t i o n Solution Solution
原题啊。。。
C o d e Code Code
#include<queue>
#include<cstdio>
#include<cctype>
#define LL long long
using namespace std;int n,m,f[2001][2001];
inline LL read()
{
char c;int f=0,d=1;
while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
return d*f;
}
signed main()
{
n=read();m=read();f[0][0]=1;
for(register int i=0;i<=n;i++)
for(register int j=0;j<=m;j++)
{
if(i+j==0) continue;
if(j<m&&i!=0) (f[i][j]+=f[i-1][j+1]+f[i][j-1])&=0xfff;
else (f[i][j]+=f[i][j-1])&0xfff;
}
printf("%d",f[n][0]&0xfff);
}