2019.4.27 提高B组 T3 nssl-1318 地铁重组

版权声明:虽然本蒟蒻很菜,但各位dalao转载请注明出处谢谢。 https://blog.csdn.net/xuxiayang/article/details/89601957

D e s c r i p t i o n Description

n n 个数要入栈然后出栈,但这个栈只能容纳 m m 个数,求出栈顺序数,对4096取模

n , m 2000 n,m\leq 2000


S o l u t i o n Solution

原题啊。。。


C o d e 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);
}

猜你喜欢

转载自blog.csdn.net/xuxiayang/article/details/89601957
今日推荐