现在的位置: 首页 > 综合 > 正文

1925: [Sdoi2010]地精部落 (动态规划)

2018年01月13日 ⁄ 综合 ⁄ 共 502字 ⁄ 字号 评论关闭
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>

#define ll long long
#define inf 1000000000
using namespace std;

inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x*f;
}

int n, p, f[2][4501];

int main() {
    n = read();
    p = read();
    f[1][1] = 1;
    for (int i = 2; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            int x = i & 1;
            f[x][j] = (f[x][j - 1] + f[x^1][i - j]) % p;
        }

    printf("%d", n == 1 ? 1 % p : f[n & 1][n]*2 % p);
    return 0;
}

抱歉!评论已关闭.