前言
考完以后感觉炸了,结果还好(大雾,竟然没有垫底 5+80+20=105(21/52)
题意
对于任意的$1\leq k \leq N$,求有多少个恰好有$k$个叶子节点的二叉树,满足每个节点要么没有子节点,要么有两个子节点,同时不存在一个叶子节点,使得根到它的路径上有不少于$M$条向左的边。 答案对$998244353$取模。
思路
此题发下来时语意不清,上标黑字体还有错误(大雾 搞了半天还没看懂 于是自己瞎推了一下样例:
1 2
| Input:3 5 Output:1 1 2 4 8
|
(似乎发现了什么,忽略$M$的限制,打表竟然打出了像卡特兰数的东西……于是转移到平面直角坐标系,dp 设$f[i][j]$表示$i$个叶子节点,往左的边的数量与往右边的数量之差为$j$。 若$j<m-1$,那么$f[i][j+1]+=f[i][j]$ 若$j>0$,那么$f[i+1][j-1]+=f[i][j]$ 画图大概是这样的:
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #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; char Rd[S],*A,*B; #define pc putchar public: #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%10+'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; }
|