dp
搬题解~~:http://blog.csdn.net/aarongzk/article/details/44871391
#include<cstdio> using namespace std; const int N = 5010; int n, p, pre; int f[2][N]; int main() { scanf("%d%d", &n, &p); f[pre][1] = 1; for(int i = 2; i <= n; ++i) { pre ^= 1; for(int j = 1; j <= n; ++j) f[pre][j] = (f[pre][j - 1] + f[pre ^ 1][i - j]) % p; } if(n == 1) puts("1"); else printf("%d ", (f[pre][n] << 1) % p); return 0; }