传送门: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. java中的运算(2013-05-03-bd 写的日志迁移

    // ++自加 --自减 int a=9; a++; // a=a+1; System.out.println(a); // a=10 a--; // a=a-1 System.out.println ...

  2. Pandas 数值计算和统计基础

    1.(1) # 基本参数:axis.skipna import numpy as np import pandas as pd df = pd.DataFrame({'key1':[4,5,3,np. ...

  3. [BZOJ4196]软件包管理器(树链剖分)

    [BZOJ4196] install x-> 询问根节点到x路径上0的个数,然后全变1 uninstall x-> 询问x子树(包括x)中1的个数,然后全边0 Code #include ...

  4. J.U.C 系列 Tools之Executors

    上个章节说了Tools中的其他四个工具类,本节我们来看一看工具类中的老大Executors,为什么说它是老大,肯定是因为他的功能最多最强大. 一 Executors是什么 Executors 是一个线 ...

  5. AD9 设置网络标号作用域

    http://blog.sina.com.cn/s/blog_99c8ec600102uxul.html 1.版本:Altium Designer 10 2.原因:在进行多原理图设计时, 不同原理图之 ...

  6. 获取<考试>博文密码!o(*≧▽≦)ツ

    就是CJ高二组通用的密码 如果你想知道,请联系QQ,3057244225,或者直接面对面问博主(...) 是我们的内部材料,原创题目是不能外传的.请谅解. 当然如果是原题的话我们是不会上锁的啦

  7. AD RMS总结

    AD RMS 认识篇 AD RMS(Active Directory Right Mangement Servic)活动目录权限服务. 首先我通过了解AD RMS的用途去深入学习AD RMS.在过去用 ...

  8. spark发现新词

    package com.icklick.spark.wordSegment import org.apache.log4j.{ Level, Logger } import org.apache.sp ...

  9. [译]14-spring 集合元素的注入

    前面的文章已经介绍了如何往bean里面注入原始类型和引用类型.我们使用bean元素的contructor-arg或property子 元素的value属性注入java原始类型;同理,我们可以使用bea ...

  10. Python全栈工程师(集合、函数)

     ParisGabriel     感谢 大家的支持  你们的阅读评价就是我最好的动力  我会坚持把排版内容以及偶尔的错误做的越来越好        每天坚持 一天一篇 点个订阅吧  灰常感谢    ...