POJ3046--Ant Counting(动态规划)
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
* Lines 2..A+1: Each line contains a single integer that is an ant type present in the hive
Output
Sample Input
3 5 2 3
1
2
2
1
3
Sample Output
10
Hint
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(动态规划)的更多相关文章
- [poj3046][Ant counting数蚂蚁]
题目链接 http://noi.openjudge.cn/ch0206/9289/ 描述 Bessie was poking around the ant hill one day watching ...
- poj-3046 Ant Counting【dp】【母函数】
题目链接:戳这里 题意:有A只蚂蚁,来自T个家族,每个家族有ti只蚂蚁.任取n只蚂蚁(S <= n <= B),求能组成几种集合? 这道题可以用dp或母函数求. 多重集组合数也是由多重背包 ...
- [poj3046]Ant Counting(母函数)
题意: S<=x1+x2+...+xT<=B 0<=x1<=N1 0<=x2<=N2 ... 0<=xT<=NT 求这个不等式方程组的解的个数. 分析: ...
- 2019.01.02 poj3046 Ant Counting(生成函数+dp)
传送门 生成函数基础题. 题意:给出nnn个数以及它们的数量,求从所有数中选出i∣i∈[L,R]i|i\in[L,R]i∣i∈[L,R]个数来可能组成的集合的数量. 直接构造生成函数然后乘起来f(x) ...
- poj3046 Ant Counting——多重集组合数
题目:http://poj.org/problem?id=3046 就是多重集组合数(分组背包优化): 从式子角度考虑:(干脆看这篇博客) https://blog.csdn.net/viphong/ ...
- 【POJ - 3046】Ant Counting(多重集组合数)
Ant Counting 直接翻译了 Descriptions 贝西有T种蚂蚁共A只,每种蚂蚁有Ni只,同种蚂蚁不能区分,不同种蚂蚁可以区分,记Sum_i为i只蚂蚁构成不同的集合的方案数,问Sum_k ...
- poj 3046 Ant Counting
Ant Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4982 Accepted: 1896 Desc ...
- BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 56 Solved: 16[S ...
- 1630/2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 85 Solved: 40[S ...
- poj 3046 Ant Counting(多重集组合数)
Ant Counting Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total ...
随机推荐
- 史上最全的MSSQL复习笔记
1.什么是SQL语句 SQL语言,结构化的查询语言(Structured Query Language),是关系数据库管理系统的标准语言.它是一种解释语言,写一句执行一句,不需要整体编译执行. 语法特 ...
- 13.Mysql触发器
13.触发器13.1 创建触发器定义:触发器是与表有关的数据库对象,在满足定义条件时触发,并执行触发器中定义的语句集合.语法:create trigger 触发器名称 触发时机 触发事件 on 表名 ...
- 4C - 七夕节
七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" 人们纷纷来到告示前,都想知道谁才是自己 ...
- Gulp应用场景
转自:Gulp教程之:Gulp能做什么,前端装逼为何要用它 我们先说说 平时web开发遇到的一些场景 和 苦恼无奈的情况: JavaScript和CSS的版本问题 我们都知道 JavaScript ...
- mysql 5.7.17 建立主从数据库
---恢复内容开始--- 1.确定主/从数据库地址; 2.将主数据库的database dump出来 windows平台用workbench; 其他可以参考: 这位同仁写的比较详细了.我就不谢了.打开 ...
- 20172306 《Java程序设计与数据结构》第七周学习总结
20172306<Java程序设计>第七周学习总结 教材学习内容总结 这一章的标题是继承.主要学习了有关继承的相关知识.其中在这五节中,我学到了以下几点: 1.继承主要表达的是" ...
- 无法创建.gitignore文件,提示必须输入文件名称
If you're using Windows it will not let you create a file without a filename in Windows Explorer. It ...
- 【UI测试】--多窗口&系统资源
- sql2005性能优化(在32位系统上突破2G内存使用量的方法) .
转载自http://blog.csdn.net/soldierluo/article/details/6589743 服务器磁盘为(SAS)IBM组成RAID0+1,SQL2K5只识别4G内存,实际只 ...
- Python内置logging模块
最近调试Python代码比较多,发现logging模块很好用. 我的用法如下: import logging logging.basicConfig(level=logging.INFO, forma ...