代码:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 2004, mod = 998244853; int n, m; ll dp[maxn][maxn], f[maxn][maxn], C[maxn<<1][maxn<<1]; void init() { C[0][0] = 1LL; for(int i = 1; i <= n + m; ++i) { C[i][0] = 1LL; for(int j = 1; j <= i; ++j) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod; } } int main() { scanf("%d%d", &n, &m); init(); for(int i = 1; i <= m; ++i) { f[0][i] = 1; for(int j = 1; j <= i; ++j) f[j][i] = (f[j-1][i] + f[j][i-1]) % mod; } for(int i = 1; i <= n; ++i) dp[i][0] = i; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) dp[i][j] = (((dp[i-1][j] + C[i+j-1][j] + dp[i][j-1] - C[i+j-1][i] + f[i][j-1]) % mod) + mod) % mod; printf("%lld\n", dp[n][m]); return 0; }
来源:博客园
作者:Mr_Joker
链接:https://www.cnblogs.com/Joker-Yza/p/11613901.html