bzoj1925

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\n", (f[pre][n] << 1) % p);
    return 0;
}
View Code

 

posted @ 2017-10-25 16:38  19992147  阅读(109)  评论(0编辑  收藏  举报