设为首页 加入收藏

TOP

BZOJ1925: [Sdoi2010]地精部落(dp)
2018-12-06 18:09:18 】 浏览:73
Tags:BZOJ1925: Sdoi2010 部落

题意

题目链接

Sol

不会做Orzzzz

想到了和题解一样的方程,但是根本不会转移

具体题解看这里

大致思路就是先推一波性质,然后对于最后一个位置上的数\(i\),分两种情况讨论一下:与\(i - 1\)相邻 / 不相邻,

#include<bits/stdc++.h>
#define chmin(x, y) (x = x < y ? x : y)
#define chmax(x, y) (x = x > y ? x : y)
using namespace std;
const int MAXN = 5001, INF = 2e9 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int f[2][MAXN], N, mod;
int add(int x, int y) {
    return x + y >= mod ? x + y - mod : x + y;
}
int add2(int &x, int y) {
    return x = (x + y >= mod ? x + y - mod : x + y);
}
int mul(int x, int y) {
    return 1ll * x * y % mod;
}
int main() {   
    N = read(), mod = read();
    f[0][1] = 1; int o =1;
    for(int i = 2; i <= N; i++, o ^= 1) {
        fill(f[o] + 1, f[o] + N + 1, 0);
        for(int j = 1; j <= i; j++) 
            f[o][j] = add(f[o][j - 1], f[o ^ 1][i - (j - 1)]);      
    } 
    int ans = 0;
    for(int i = 1; i <= N; i++) add2(ans, f[o ^ 1][i]);
    printf("%d\n", mul(ans, 2));
    return 0;
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇BZOJ1927: [Sdoi2010]星际竞速(最.. 下一篇异常处理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目