bzoj1925地精部落——数学
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1925
真是精妙的递推式。。。好难想到啊;
详见这位的博客:https://www.cnblogs.com/Narh/p/9135070.html
代码如下:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,p,f[3][4200],ans; int main() { scanf("%d%d",&n,&p); f[0][1]=1; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) f[i%2][j]=(f[i%2][j-1]+f[(i+1)%2][i-j+1])%p; for(int i=1;i<=n;i++) (ans+=f[n%2][i])%=p; (ans<<=1)%=p; printf("%d",ans); return 0; }