传送门: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 + ;
const int mod = 1e6; # define RG register
# define ST static int m, n, A, B;
int a[M], bel[M], sum[M];
int f[][], s[][]; int main() {
cin >> m >> n >> A >> B;
for (int i=; i<=n; ++i) {
scanf("%d", &bel[i]);
a[bel[i]] ++;
}
int pre = , cur = ;
f[pre][] = ;
for (int i=; i<=n; ++i) s[pre][i] = ;
for (int i=; i<=m; ++i) {
for (int j=; j<=n; ++j) {
if(a[i] < j) f[cur][j] = (s[pre][j] - s[pre][j-a[i]-] + mod) % mod;
else f[cur][j] = s[pre][j];
if(j == ) s[cur][j] = f[cur][j];
else s[cur][j] = (s[cur][j-] + f[cur][j]) % mod;
}
swap(pre, cur);
}
int ans = (s[pre][B] - s[pre][A-] + mod) % mod;
cout << ans << endl;
return ;
}

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

  1. 【BZOJ1630/2023】[Usaco2007 Demo]Ant Counting DP

    [BZOJ1630/2023][Usaco2007 Demo]Ant Counting 题意:T中蚂蚁,一共A只,同种蚂蚁认为是相同的,有一群蚂蚁要出行,个数不少于S,不大于B,求总方案数 题解:DP ...

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

    bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁&&bzoj1630[Usaco2007 Demo]Ant Counting 题意: t个族群,每个族群有 ...

  3. bzoj1630 [Usaco2007 Demo]Ant Counting

    Description Bessie was poking around the ant hill one day watching the ants march to and fro while g ...

  4. 【BZOJ】1630: [Usaco2007 Demo]Ant Counting(裸dp/dp/生成函数)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1630 题意,给你n种数,数量为m个,求所有的数组成的集合选长度l-r的个数 后两者待会写.. 裸dp ...

  5. bzoj 1630: [Usaco2007 Demo]Ant Counting【dp】

    满脑子组合数学,根本没想到dp 设f[i][j]为前i只蚂蚁,选出j只的方案数,初始状态为f[0][0]=1 转移为 \[ f[i][j]=\sum_{k=0}^{a[i]}f[i-1][j-k] \ ...

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

    2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 85  Solved: 40[S ...

  7. BZOJ 2023 [Usaco2005 Nov]Ant Counting 数蚂蚁:dp【前缀和优化】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2023 题意: 有n个家族,共m只蚂蚁(n <= 1000, m <= 1000 ...

  8. bzoj1630 / bzoj2023 [Usaco2005 Nov]Ant Counting 数蚂蚁

    Description     有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个 ...

  9. bzoj 2023: [Usaco2005 Nov]Ant Counting 数蚂蚁【生成函数||dp】

    用生成函数套路推一推,推完老想NTT--实际上把这个多项式乘法看成dp然后前缀和优化一下即可 #include<iostream> #include<cstdio> using ...

随机推荐

  1. Laravel系列之CMS系统学习 — 角色、权限配置【1】

    一.后台Admin模块 后台管理是有管理员的,甚至超级管理员,所以在设计数据表的时候,就会有2个方案,一个方案是共用users数据表,添加is_admin,is_superAdmin字段来进行验证,或 ...

  2. POJ 1286 Pólya定理

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9162   Accepted: 3786 ...

  3. POJ:3579-Median(二分+尺取寻找中位数)

    Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9201 Accepted: 3209 Description Gi ...

  4. Kafka安装和常用操作命令

    Kafka安装: 下载kafka_2.10-0.8.2.1 1.关闭防火墙 2.修改配置文件  server.properties broker.id=1log.dirs= /usr/kafka_2. ...

  5. laravel5.5用户认证源码分析

    目录 1. 生成相关文件和配置 2. 分析路由文件 3. 以登陆开始为例,分析auth到底是怎么工作的 3.1 分析登录文件 3.2 分析门面Auth. 1. 生成相关文件和配置 快速生成命令 php ...

  6. MyEclipse - 问题集 - Workspace in use or cannot be created, choose a different one(转)

    转:http://wsfly.iteye.com/blog/1044986 eclipse 使用一段时间后,有时会因为一些故障自己就莫名奇妙的关闭了,再打开时有时没有问题,有时有会提示错误 Works ...

  7. 《Cracking the Coding Interview》——第16章:线程与锁——题目4

    2014-04-27 20:06 题目:设计一个类,只有在不产生死锁的时候才分配资源. 解法:不太清楚这个题是要分配何种资源,以何种形式?所以没能动手写个可运行的代码,只是闲扯了几句理论分析. 代码: ...

  8. elk-logstash: window下指定jdk目录

    \bin\logstash.bat文件中, SETLOCAL的后面,CALL "%SCRIPT_DIR%\setup.bat" 的前面增加一行: @echo off SETLOCA ...

  9. Djano之写api使用django_rest_framework【海瑞博客】

    使用django rest framework 可以更快速和友好的编写api,当然网上有很多教程,对于高手来说相对很简单,对于新手来说,根本搞不明白.那是你没有搞明白你自己的职责,做为后端,我们只要提 ...

  10. nosetests

    1.nosetests 执行出测试报告 提前安装 插件nose-html系列插件   nosetests -v --with-html-output --html-out-file=报告名.html ...