poj-3046-dp
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6829 | Accepted: 2514 |
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
Source
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define LL long long
const LL MOD=;
LL f[][+];
int tot[];
int main()
{
int T,A,S,B;
int i,j,k,n,m;
while(cin>>T>>A>>S>>B){
memset(tot,,sizeof(tot));
for(i=;i<=A;++i){
scanf("%d",&n);
tot[n]++;
}
int cur=;
LL ans=;
f[cur][]=;
for(i=;i<=A;++i) f[cur][i]=; for(i=;i<=T;++i){
cur^=;
f[cur][]=;
for(j=;j<=A;++j){
int tt=j-tot[i]-;
if(j<=tot[i]){
f[cur][j]=(f[cur][j-]+f[cur^][j])%MOD;
}
else{
f[cur][j]=(f[cur][j-]+f[cur^][j]-f[cur^][j--tot[i]]+MOD)%MOD;
}
}
}
ans=(f[cur][B]-f[cur][S-]+MOD)%MOD;
cout<<ans<<endl;
}
return ;
}
poj-3046-dp的更多相关文章
- poj 3046 Ant Counting (DP多重背包变形)
题目:http://poj.org/problem?id=3046 思路: dp [i] [j] :=前i种 构成个数为j的方法数. #include <cstdio> #include ...
- DP:Ant Counting(POJ 3046)
数蚂蚁 题目大意:一只牛想数蚂蚁,蚂蚁分成很多组,每个组里面有很多只蚂蚁,现在问你有多少种组合方式 (说白了就是问1,1,1,...,2...,3...,4...)这些东西有多少种排列组合方式 这一道 ...
- 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——多重集合的背包
题目:http://poj.org/problem?id=3046 多重集合的背包问题. 1.式子:考虑dp[ i ][ j ]能从dp[ i-1 ][ k ](max(0 , j - c[ i ] ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- poj 1609 dp
题目链接:http://poj.org/problem?id=1609 #include <cstdio> #include <cstring> #include <io ...
- POJ 1037 DP
题目链接: http://poj.org/problem?id=1037 分析: 很有分量的一道DP题!!! (参考于:http://blog.csdn.net/sj13051180/article/ ...
- Jury Compromise POJ - 1015 dp (标答有误)背包思想
题意:从 n个人里面找到m个人 每个人有两个值 d p 满足在abs(sum(d)-sum(p)) 最小的前提下sum(d)+sum(p)最大 思路:dp[i][j] i个人中 和 ...
随机推荐
- 基于.net core2.1开发遇到的问题记录以及解决方案
问题1:升级EFCore 到2.1一直报'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFac ...
- 基于java的网络爬虫框架(实现京东数据的爬取,并将插入数据库)
原文地址http://blog.csdn.net/qy20115549/article/details/52203722 本文为原创博客,仅供技术学习使用.未经允许,禁止将其复制下来上传到百度文库等平 ...
- java 将小数拆分为两部分+浮点型精度丢失问题
问题:将一个String类型的小数拆分为整数部分和小数部分,如9.9拆分为9和0.9 1.将小数的整数和小数部分拆分开 public float numberSub(String totalMoney ...
- Centos上安装python3.5以上版本
一.准备工作: yum install zlib-devel yum install openssl-devel 二.安装python3.5 wget https://www.python.org/f ...
- Submine Text 快捷键
Ctrl+Shift+P:打开命令面板 Ctrl+P:搜索项目中的文件 Ctrl+G:跳转到第几行 Ctrl+W:关闭当前打开文件 Ctrl+Shift+W:关闭所有打开文件 Ctrl+Shift+V ...
- presto 0.166安装部署
系统:linux java:jdk 8,64-bit Connector:hive 分布式,node1-3 node1:Coordinator . Discovery service node2-3: ...
- myeclipse自动生成相应对象接收返回值的快捷键
在你要自动生成返回值对象的那一行的末尾(注意一定要将光标点到最后),按Alt+Shift+L:就可以了.
- iOS开发之HelloKit代码片段
完整代码托管:https://github.com/1042710553/HelloKit.git /************************/plist/****************** ...
- Apache 部署HTTPS
Apache 部署HTTPS 系统:Linux Centos 7.4 x64 应用:Apache 2.4.6 需要安装:mod_ssl 注:确认开启 Include conf/extra/httpd- ...
- 20145302张薇《Java程序设计》第三周学习总结
20145302张薇<Java程序设计>第三周学习总结 教材学习内容总结 第四章 定义类 一个原始码中有多少类就会有多少.class文档. 标准类 使用java.util.scanner让 ...