跳到正文

个人记录

草稿纸

WhoChange约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年1月21日
收录
2026年1月21日
更新
2026年11月16日
篇幅
约 1 分钟

版本

  1. v1当前
C++
// Change's code
#include <iostream>
#include <algorithm>
using namespace std;
int n, p;
int f[2010][2010];
int dfs(int a, int b){
	if(f[a][b]) return f[a][b];
	return f[a][b] = (2*dfs(a-1, b) + n * dfs(b, a-1)) % p;
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> p;
	f[1][0] =  1;
	printf("%d", dfs(n, n));
	return 0;
}
原文