c/c++语言开发共享BZOJ1925: [Sdoi2010]地精部落(dp)

题意 “题目链接” Sol 不会做Orzzzz 想到了和题解一样的方程,但是根本不会转移 具体题解看 “这里” 吧 大致思路就是先推一波性质,然后对于最后一个位置上的数$i$,分两种情况讨论一下:与$i 1$相邻 / 不相邻, cpp include define chmin(x, y) (x = …


题意

题目链接

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("%dn", mul(ans, 2));     return 0; }

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/606066.html

(0)
上一篇 2021年5月13日
下一篇 2021年5月13日

精彩推荐