题目链接

http://noi.openjudge.cn/ch0206/9289/

描述

Bessie was poking around the ant hill one day watching the ants march to and fro while gathering food. She realized that many of the ants were siblings, indistinguishable from one another. She also realized the sometimes only one ant would go for food, sometimes a few, and sometimes all of them. This made for a large number of different sets of ants!

Being a bit mathematical, Bessie started wondering. Bessie noted that the hive has T (1 <= T <= 1,000) families of ants which she labeled 1..T (A ants altogether). Each family had some number Ni (1 <= Ni <= 100) of ants.

How many groups of sizes S, S+1, ..., B (1 <= S <= B <= A) can be formed?

While observing one group, the set of three ant families was seen as {1, 1, 2, 2, 3}, though rarely in that order. The possible sets of marching ants were:

3 sets with 1 ant: {1} {2} {3}
5 sets with 2 ants: {1,1} {1,2} {1,3} {2,2} {2,3}
5 sets with 3 ants: {1,1,2} {1,1,3} {1,2,2} {1,2,3} {2,2,3}
3 sets with 4 ants: {1,2,2,3} {1,1,2,2} {1,1,2,3}
1 set with 5 ants: {1,1,2,2,3}

Your job is to count the number of possible sets of ants given the data above.


输入

* Line 1: 4 space-separated integers: T, A, S, and B

* Lines 2..A+1: Each line contains a single integer that is an ant type present in the hive


输出

* Line 1: The number of sets of size S..B (inclusive) that can be created. A set like {1,2} is the same as the set {2,1} and should not be double-counted. Print only the LAST SIX DIGITS of this number, with no leading zeroes or spaces.


样例输入

3 5 2 3
1
2
2
1
3

样例输出

10

  英文题目也是真的难懂,理解了很久,其实题目意思挺简单的,就是给你s个t种蚂蚁,每种蚂蚁有一定的数量,然后去求用这些种蚂蚁组成s——b之间长的,情况数有多少。

  仔细理解的话可以发现,我们可以把这个看成背包问题,对于这t种蚂蚁,如果其中一组数量为k,那么就有k+1种情况,既不选这种蚂蚁,选一个,选两个……选k个。

  那么我们就套用背包模板,先枚举种类,再枚举序列长度,第三层枚举选的个数。每种区间,第三层枚举的选不同个数的情况之和,那么状态转移方程就是

    f[i][j]+=f[i-1][j-k]   //f[i][j]表示前i个种类中选j长的序列的情况数。

所以当第i种选k个时,那么情况数就是前i-1种选j-k个的情况数,因为然后再枚举k,k去不同数时的情况加起来,就是前i种选j长的序列的情况数。

注意:一定要给f数组整上一个开始的值,不然怎么加都是0;所以我们把前i种选0的情况赋值成1。

最后附上代码

 #include<cstdio>
#include<iostream>
using namespace std;
int n,a,s,b,num[],f[][];
int main()
{
scanf("%d%d%d%d",&n,&a,&s,&b);
for(int i=,t;i<=a;++i)
{
scanf("%d",&t);
num[t]++;
}
for(int i=;i<=n;++i)
{
f[i][]=;
}
for(int i=;i<=n;++i)
{
for(int j=;j<=b;++j)
{
for(int k=;k<=num[i];++k)
{
if(j>=k)
f[i][j]=f[i][j]+f[i-][j-k];
}
}
}
int ans=;
for(int i=s;i<=b;++i)
{
ans+=f[n][i];
}
printf("%d",ans);
return ;
}

 

[poj3046][Ant counting数蚂蚁]的更多相关文章

  1. BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

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

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

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

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

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

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

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

  5. BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁(dp)

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

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

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

  7. 【noi 2.6_9289】Ant Counting 数蚂蚁{Usaco2005 Nov}(DP)

    题意:有M个家族的蚂蚁,各Ni只(互相相同).问选出 l~r 只的不同方案数. 解法:很基础的一种DP,不要被"排列组合"所迷惑了啊~我之前接触过这个类型,可惜又忘了,一定要记住! ...

  8. BZOJ 1630/2023 Ant Counting 数蚂蚁

    DP. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  9. 【bzoj2023/1630】[Usaco2005 Nov]Ant Counting 数蚂蚁 dp

    题解: 水题 f[i][j] 前i种用了j个,前缀和优化就可以了

随机推荐

  1. 【亲测有效】Github无法访问或者访问速度的解决方案

    我相信,很多朋友都遇到了 Github 访问速度过慢的问题,我也是在此记下笔记,方便以后拿来使用. 第一步.修改Hosts 通过问题的搜索了解到 github 访问很慢一般通过修改 hosts 文件解 ...

  2. Mongo 开发笔记

    时间 程序的时间是本地时间 ,数据库中的时间是 ISO 标准时间 . ISO时间 + 8 小时 = 本地时间(北京时间 ) Java驱动会自动做转化. 语法 数组查询 数据查询使用 elemMatch ...

  3. Mac下通过VMware Fusion安装centos虚拟机操作记录

    下面介绍下利用VMware Fusion工具在Mac上安装centos虚拟机的做法:1)下载VMware Fusion工具下载地址(包括注册码):http://www.macx.cn/thread-2 ...

  4. beta阶段测试基本概况对应机型硬件信息

    机型测试概况 测试结果 测试终端数 品牌分布分析 系统分布分析 分辨率分布 未执行 1 联想 4.0.3 480*800 安装失败 1 联想 4.2.1 480*854 通过 119 华为, 三星, ...

  5. 【Beta版本发布】爬虫队长装备全面更新!

    一.Beta阶段目标回顾 1.为了解决Alpha阶段线程异常泛滥的问题,我们需要一个线程池. 2.为了爬取得到的文件正确可用,我们需要一个异常清理器. 3.为了不间断爬取,管理员不必频繁运行程序点,我 ...

  6. Linux内核分析——可执行程序的装载

    链接的过程 首先运行C预处理器cpp,将C的源程序(a.c)翻译成ASCII码的中间文件(a.i) 接着C编译器ccl,将a.i翻译成ASCII汇编语言文件a.s 接着运行汇编器as,将a.s翻译成可 ...

  7. 基于SSH框架的在线考勤系统开发的质量属性

    我要开发的是一个基于SSH框架的在线考勤系统. 质量属性是指影响质量的相关因素,下面我将分别从6个系统质量属性(可用性,易用性,可修改性,性能,安全性,可测试性)来分析我的系统,以及如何实现这些质量属 ...

  8. 网络:LVS负载均衡原理

    LB集群的架构和原理很简单,就是当用户的请求过来时,会直接分发到Director Server上,然后它把用户的请求根据设置好的调度算法,智能均衡地分发到后端真正服务器(real server)上.为 ...

  9. personal project

    words count program 统计文本文件的字符数,单词数和行数. 实现一个统计程序,他能正确的统计程序文件中的字符数,单词数和行数. 源码链接 https://github.com/sup ...

  10. “数学口袋精灵”App的第三个Sprint计划----开发日记

    一.现状 上一阶段基本完成一个小游戏,游戏具有:随机产生算式,判断对错功能.通过轻快的背景音乐,音效,给玩家提供一个良好的氛围.   二.任务认领 完成界面,基本功能后的后续任务: 冯美欣:设计&qu ...