poj 3046 Ant Counting
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 4982 | Accepted: 1896 |
Description
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>
using namespace std;
const int MOD=;
const int T_MAX=,A_MAX=;
int family[T_MAX];
int dp[][A_MAX+];
int main() {
int T,A,S,B;
while (cin >>T>> A>>S>>B) {
memset(family, , sizeof(family));
for (int i = ;i < A;i++) {
int index;
cin >> index;
family[index]++;
}
int total = ;
dp[][] = ;//从0个家族取出0只蚂蚁,只有一种可能
for (int i = ;i <= T;i++) {
total += family[i];
int cur =i& ;
int pre = (i - ) & ;
memset(dp[cur],,sizeof(dp[cur]));//清除上次记录
for (int k = ;k <= family[i];k++) {
for (int j = total;j >= k;j--) {//这j只蚂蚁总数不能超过这几个家族蚂蚁的总数
dp[cur][j] =(dp[cur][j]+ dp[pre][j - k])%MOD;
}
}
}
int cur = T&;
int result=;
for (int i = S;i <= B;i++) {
result =(result+ dp[cur][i])%MOD;
}
cout << result << endl;
memset(dp[(T - ) & ], , sizeof(dp[(T - ) & ]));
}
return ;
}
poj 3046 Ant Counting的更多相关文章
- poj 3046 Ant Counting(多重集组合数)
Ant Counting Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total ...
- poj 3046 Ant Counting (DP多重背包变形)
题目:http://poj.org/problem?id=3046 思路: dp [i] [j] :=前i种 构成个数为j的方法数. #include <cstdio> #include ...
- poj 3046 Ant Counting——多重集合的背包
题目:http://poj.org/problem?id=3046 多重集合的背包问题. 1.式子:考虑dp[ i ][ j ]能从dp[ i-1 ][ k ](max(0 , j - c[ i ] ...
- POJ 3046 Ant Counting ( 多重集组合数 && 经典DP )
题意 : 有 n 种蚂蚁,第 i 种蚂蚁有ai个,一共有 A 个蚂蚁.不同类别的蚂蚁可以相互区分,但同种类别的蚂蚁不能相互区别.从这些蚂蚁中分别取出S,S+1...B个,一共有多少种取法. 分析 : ...
- POJ 3046 Ant Counting DP
大致题意:给你a个数字,这些数字范围是1到t,每种数字最多100个,求问你这些a个数字进行组合(不包含重复),长度为s到b的集合一共有多少个. 思路:d[i][j]——前i种数字组成长度为j的集合有多 ...
- POJ 3046 Ant Counting(递推,和号优化)
计数类的问题,要求不重复,把每种物品单独考虑. 将和号递推可以把转移优化O(1). f[i = 第i种物品][j = 总数量为j] = 方案数 f[i][j] = sigma{f[i-1][j-k], ...
- 【POJ - 3046】Ant Counting(多重集组合数)
Ant Counting 直接翻译了 Descriptions 贝西有T种蚂蚁共A只,每种蚂蚁有Ni只,同种蚂蚁不能区分,不同种蚂蚁可以区分,记Sum_i为i只蚂蚁构成不同的集合的方案数,问Sum_k ...
- 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 ...
随机推荐
- 2015南阳CCPC E - Ba Gua Zhen 高斯消元 xor最大
Ba Gua Zhen Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description During the Three-Kingdom perio ...
- codeforces Gym 100500C C. ICPC Giveaways 排序
Problem C. ICPC GiveawaysTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1005 ...
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- MRuby 编译笔记
专注于嵌入式脚本的MRuby在Windows下的编译笔记: 环境: OS: Windows 8.1, 使用 VS Express 2013 for Desktop. 材料: MRuby : 下载源码就 ...
- [RxJS] Introduction to RxJS Marble Testing
Marble testing is an expressive way to test observables by utilizing marble diagrams. This lesson wi ...
- Helpers\GeoCode
Helpers\GeoCode This function connects to google maps and retrieves the lat/lon of the address provi ...
- centos 配置NFS服务器
转载:http://boloveyo.blog.163.com/blog/static/203926187201232383956558/ 系统是CentOS5.6,假设NFS Server IP为1 ...
- 一个开源音乐播放器,低仿QQ音乐!
有暇,弄了个音乐播放器,页面效果整体上参考了QQ音乐,相关API使用了易源数据提供的相关接口(https://www.showapi.com/api/lookPoint/213),在此表示感谢.先来看 ...
- 转摘:常用ubuntu 关机,重启,注销命令
1.关机命令 shutdown 好像ubuntu的终端中默认的是当前用户的命令,只是普通用户,因此在终端器中可以使用sudo -sh 转换到管理员root用户下执行命令. 1).shutdown –h ...
- 记录asp.net网站停止运行原因的代码
记录网站是什么原因导致停止运行还是有必要的,下面是具体的实现方式. protected void Application_End(object sender, EventArgs e) { Recor ...