bzoj1630/2023 [Usaco2007 Demo]Ant Counting

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj1630/2023 [Usaco2007 Demo]Ant Counting相关的知识,希望对你有一定的参考价值。

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1630

http://www.lydsy.com/JudgeOnline/problem.php?id=2023

【题解】

直接dp,f[i,j]表示第i个种族选了j只蚂蚁的方案数,转移枚举这个种族选择的方案。

然后可以前缀和+滚动数组

技术分享
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e6;

# define RG register
# define ST static

int m, n, A, B;
int a[M], bel[M], sum[M];
int f[2][100010], s[2][100010];

int main() {
    cin >> m >> n >> A >> B;
    for (int i=1; i<=n; ++i) {
        scanf("%d", &bel[i]);
        a[bel[i]] ++;
    }
    int pre = 0, cur = 1;
    f[pre][0] = 1;
    for (int i=0; i<=n; ++i) s[pre][i] = 1;
    for (int i=1; i<=m; ++i) {
        for (int j=0; j<=n; ++j) {
            if(a[i] < j) f[cur][j] = (s[pre][j] - s[pre][j-a[i]-1] + mod) % mod;
            else f[cur][j] = s[pre][j];
            if(j == 0) s[cur][j] = f[cur][j];
            else s[cur][j] = (s[cur][j-1] + f[cur][j]) % mod;
        }
        swap(pre, cur);
    }
    int ans = (s[pre][B] - s[pre][A-1] + mod) % mod;
    cout << ans << endl; 
    return 0;
}
View Code

以上是关于bzoj1630/2023 [Usaco2007 Demo]Ant Counting的主要内容,如果未能解决你的问题,请参考以下文章

bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁*&&bzoj1630[Usaco2007 Demo]Ant Counting*

bzoj1710Usaco2007 OpenCheappal 便宜回文

[BZOJ] 1636: [Usaco2007 Jan]Balanced Lineup

bzoj 1692: [Usaco2007 Dec]队列变换

bzoj1711Usaco2007 OpenDingin 吃饭

bzoj1627[Usaco2007 Dec]穿越泥地*