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;
}

时间: 2024-08-13 21:36:28

bzoj1630/2023 [Usaco2007 Demo]Ant Counting的相关文章

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

bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁&&bzoj1630[Usaco2007 Demo]Ant Counting 题意: t个族群,每个族群有ni只蚂蚁,同族群蚂蚁没有区别.问从所有蚂蚁中选出s到b只蚂蚁有多少方案.t≤1000,ni≤100. 题解: dp,f[i][j]表示考虑第i个族群,剩下j只蚂蚁没选择.则f[i][j]=sum(f[i-1][j-k]),k=0..min(j,n[i]).然而O(n^3)会超时,注意到可以计算f[i-1][

1630/2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 85  Solved: 40[Submit][Status][Discuss] Description 有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个蚂蚁群里有时只有一只出来觅食,有时是几只,有时干脆整个蚁群一

BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 56  Solved: 16[Submit][Status] Description 有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个蚂蚁群里有时只有一只出来觅食,有时是几只,有时干脆整个蚁群一起出来.这样一来,

bzoj1629[Usaco2007 Demo]Cow Acrobats*

bzoj1629[Usaco2007 Demo]Cow Acrobats 题意: n头牛,每天牛都有体重与力量值.它们玩叠罗汉的游戏,每个牛的危险值等于它上面的牛的体重总和减去它的力量值,求所有方案中危险值最大的最小. 题解: 贪心.第i头牛比第j头牛高当且仅当i的重量-j的力量<j的重量-i的力量. 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn

Ant Counting (poj 3046 分组背包)

Language: Default Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3142   Accepted: 1246 Description Bessie was poking around the ant hill one day watching the ants march to and fro while gathering food. She realized that man

【BZOJ 1629】 [Usaco2007 Demo]Cow Acrobats

1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 657  Solved: 331 [Submit][Status] Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet p

BZOJ1628: [Usaco2007 Demo]City skyline

1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 256  Solved: 210[Submit][Status] Description The best part of the day for Farmer John's cows is when the sun sets. They can see the skyline of the distant city. Bessie w

[Usaco2007 Demo][BZOJ1628] City skyline

1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 320  Solved: 260[Submit][Status][Discuss] Description Input 第一行给出N,W 第二行到第N+1行:每行给出二个整数x,y,输入的x严格递增,并且第一个x总是1 Output 输出一个整数,表示城市中最少包含的建筑物数量 Sample Input 10 26 1 1 2 2 5

1629: [Usaco2007 Demo]Cow Acrobats

1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1023  Solved: 531[Submit][Status][Discuss] Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofe