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.

Input

* 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

Output

* 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.

Sample Input

3 5 2 3
1
2
2
1
3

Sample Output

10

Hint

INPUT DETAILS:

Three types of ants (1..3); 5 ants altogether. How many sets of size 2 or size 3 can be made?

OUTPUT DETAILS:

5 sets of ants with two members; 5 more sets of ants with three members

 
 

#include<iostream>
#include<algorithm>
#include<string.h>
int dp[][];
int num[];
#define MOD 1000000
using namespace std;
int main(){
int t,a,s,b;
cin>>t>>a>>s>>b;
for(int i=;i<=a;i++){
int x;
cin>>x;
num[x]++;
}
dp[][]=;
int total=;
for(int i=;i<=t;i++){
total+=num[i];
memset(dp[i%],,sizeof(dp[i%]));
for(int j=;j<=total;j++){
for(int k=;k<=num[i];k++){
dp[i%][j]=(dp[i%][j]+dp[(i-)%][j-k])% MOD;
}
}
}
int ans=;
for(int i=s;i<=b;i++){
ans=(ans+dp[t%][i])% MOD;
}
cout<<ans<<endl;
return ;
}

POJ3046--Ant Counting(动态规划)的更多相关文章

  1. [poj3046][Ant counting数蚂蚁]

    题目链接 http://noi.openjudge.cn/ch0206/9289/ 描述 Bessie was poking around the ant hill one day watching ...

  2. poj-3046 Ant Counting【dp】【母函数】

    题目链接:戳这里 题意:有A只蚂蚁,来自T个家族,每个家族有ti只蚂蚁.任取n只蚂蚁(S <= n <= B),求能组成几种集合? 这道题可以用dp或母函数求. 多重集组合数也是由多重背包 ...

  3. [poj3046]Ant Counting(母函数)

    题意: S<=x1+x2+...+xT<=B 0<=x1<=N1 0<=x2<=N2 ... 0<=xT<=NT 求这个不等式方程组的解的个数. 分析: ...

  4. 2019.01.02 poj3046 Ant Counting(生成函数+dp)

    传送门 生成函数基础题. 题意:给出nnn个数以及它们的数量,求从所有数中选出i∣i∈[L,R]i|i\in[L,R]i∣i∈[L,R]个数来可能组成的集合的数量. 直接构造生成函数然后乘起来f(x) ...

  5. poj3046 Ant Counting——多重集组合数

    题目:http://poj.org/problem?id=3046 就是多重集组合数(分组背包优化): 从式子角度考虑:(干脆看这篇博客) https://blog.csdn.net/viphong/ ...

  6. 【POJ - 3046】Ant Counting(多重集组合数)

    Ant Counting 直接翻译了 Descriptions 贝西有T种蚂蚁共A只,每种蚂蚁有Ni只,同种蚂蚁不能区分,不同种蚂蚁可以区分,记Sum_i为i只蚂蚁构成不同的集合的方案数,问Sum_k ...

  7. poj 3046 Ant Counting

    Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4982   Accepted: 1896 Desc ...

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

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

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

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

  10. poj 3046 Ant Counting(多重集组合数)

    Ant Counting Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total ...

随机推荐

  1. Python ctypes.windll.user32() Examples

    Example 1 Project: OSPTF   Author: xSploited   File: mouselogger.py View Source Project 7 votes def ...

  2. Kali xrdp远程桌面

    发现论坛没有该教程,在这里分享给需要的基友.源还是要更新的,楼主在网上百度的kali源,而不是linux源,比163.搜狐的源好些.首先安装xrdp: apt-get install xrdp 复制代 ...

  3. iOS.Crash.OniOS8.WhenCall[popToRootViewController]

    系统iOS 8.x, ARC. CrashCase: 在UIViewController中有一个类型为UIScrollView的实例变量scrollView, 点击UIViewController中的 ...

  4. Tinyos学习笔记(二)

    1.TinyOS communication tools java serialApp -comm serial@/dev/ttyUSB0:telosb java net.tinyos.tools.L ...

  5. NC 6系预警类型注册

    在实际开发预警任务中,因为模块是新创建的,所以开发预警,就要在相应的节点模块注册.但这样代码就得放在相应的模块中,注册个预警类型,就可以把代码直接放在自己新建的模块. .先执行新建模块语句 inser ...

  6. html里<div> <br /> <p>三者区别

    一.语法不同   -   TOP div和p是成对组合闭合标签:<br />是单一的闭合标签. 以<div>开始,</div>结束:以<p>开始,< ...

  7. Python 之异常处理机制

    python在程序运行出现错误时时有相应的反应机制 ,我们可以针对不同的错误做出不同的响应 list1 = ['a','b','c'] print(list1[4]) #>>>Ind ...

  8. boost asio 一个聊天的基本框架

    示例代码 #include "Util.h" #include "MyAsio.h" #include "TcpConnectionManager.h ...

  9. BS架构如何实现即时消息提醒

    转载地址:https://blog.csdn.net/cyjch/article/details/51506434

  10. 关于syslog日志功能详解 事件日志分析、EventLog Analyzer

    关于syslog日志功能详解 事件日志分析.EventLog Analyzer 一.日志管理 保障网络安全 Windows系统日志分析 Syslog日志分析 应用程序日志分析 Windows终端服务器 ...