zoukankan      html  css  js  c++  java
  • BZOJ1925: [Sdoi2010]地精部落(dp)

    题意

    题目链接

    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
    ", mul(ans, 2));
        return 0;
    }
    
  • 相关阅读:
    后向边
    图的割点、桥和双连通分支的基本概念
    Hihocoder 1062 最近公共祖先1
    会场问题 差分解法
    POJ2976 01分数规划 普通题
    Hihocoder 1049
    hihocoder 1050树中最长路
    Hihocoder 1055
    POJ1463
    C语言|博课作业02
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10077626.html
Copyright © 2011-2022 走看看