2019.10.6 CSP-S模拟赛T1
前言
考完以后感觉炸了,结果还好(大雾,竟然没有垫底 5 80 20=105(21/52)
题意
对于任意的1leq k leq N,求有多少个恰好有k个叶子节点的二叉树,满足每个节点要么没有子节点,要么有两个子节点,同时不存在一个叶子节点,使得根到它的路径上有不少于M条向左的边。 答案对998244353取模。
思路
此题发下来时语意不清,上标黑字体还有错误(大雾 搞了半天还没看懂
于是自己瞎推了一下样例:
代码语言:javascript复制Input:3 5
Output:1 1 2 4 8
(似乎发现了什么,忽略M的限制,打表竟然打出了像卡特兰数的东西……于是转移到平面直角坐标系,dp 设f[i][j]表示i个叶子节点,往左的边的数量与往右边的数量之差为j。 若j<m-1f[i][j 1] =f[i][j] 若j>0f[i 1][j-1] =f[i][j] 画图大概是这样的:
Code
代码语言:javascript复制#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
#define re register
#define int long long
class Quick_Input_Output{
private:
static const int S=1<<21;
// #define gc() (A==B&&(B=(A=Rd) fread(Rd,1,S,stdin),A==B)?EOF:*A )
char Rd[S],*A,*B;
#define pc putchar
public:
// #undef gc()
#define gc getchar
inline int read(){
int res=0,f=1;char ch=gc();
while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=gc();}
while(ch>='0'&&ch<='9') res=res*10 ch-'0',ch=gc();
return res*f;
}
inline void write(int x){
if(x<0) pc('-'),x=-x;
if(x<10) pc(x '0');
else write(x/10),pc(x '0');
}
#undef gc
#undef pc
}I;
#define File freopen("pa.in","r",stdin);freopen("pa.out","w",stdout);
int m,n,las,f[5010][5010];
signed main(){
File
m=I.read();n=I.read();
f[1][0]=1;
for(int i=1;i<=n;i )
for(int j=0;j<m;j ) f[i][j 1] =f[i][j],f[i][j 1]%=998244353,f[i 1][j-1] =f[i][j],f[i 1][j-1]%=998244353;
for(int i=1;i<=n;i ) I.write(f[i][0]),putchar('n');
return 0;
}