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个人中 和 ...
随机推荐
- 如何使用别人的代码 (特指在MFC里面 或者推广为C++里面)
别人写了一堆代码,给了你源代码.在C++里面 应该是 头文件(.h)和源文件(.cpp). 那么我们如何使用他们呢?? 第一步:将其包含进来 如下图 ,不论是头文件还是源文件都如此 第二步:告诉 ...
- vue——学习笔记
1.vue需要在dom加载完成之后实现实例化 eg: window.onload = function(){ new Vue({ el: '#editor', data: { input: '# he ...
- [笔记] Ubuntu 18.04安装cuda 10及cudnn 7流程
安装环境 OS:Ubuntu 18.04 64 bit 显卡:NVidia GTX 1080 任务:安装 CUDA 10及cuDNN 7 工具下载 NVidia官网下载下列文件: CUDA 10:cu ...
- find()函数
find()函数返回类型:size_type 1/S.find(T):返回T在S中第一次匹配的下标位置 2/S.find_first_of(T):返回字符串T第一个字符在S中第一次出现的下标位置 3/ ...
- 【android】activity、fragment传值例子
1:Activity篇 1.1向Activity传值 关键点在于putExtra.如果传递类的话,记得类实现Serializable接口 Intent intent = new Intent(Firs ...
- 日志处理(三) logback 手动加载(转)
本文转自:http://www.2cto.com/kf/201302/191149.html 一共两个java文件,第一个是例子,第二个是配置文件加载类; LogbackTest.java /* * ...
- 20145316《Java程序设计》实验二报告
20145316<Java程序设计>实验二报告 一.实验目的与要求 1.初步掌握单元测试和TDD. 2.理解并掌握面向对象三要素:封装.继承.多态. 3.初步掌握UML建模. 4.熟悉S. ...
- Java RSA公钥加密,私钥解密算法的尝试
https://www.cnblogs.com/liemng/p/6699257.html 写这篇博客其实是有点意外的,来源最初也算是入职当前这家公司算吧,由于项目要求数据几乎都进行了加密(政府项目么 ...
- Python3.x:正则 re.findall()的用法
Python3.x:正则 re.findall()的用法 概念: 语法:findall(pattern, string, flags=0) 说明:返回string中所有与pattern相匹配的全部字串 ...
- snapshot与release
总结自:https://www.jianshu.com/p/084fd2408d9a 这两个概念是用于描述jar包,jar包提供给其他系统作为依赖. 1. snapshot版本代表不稳定.尚处于开发中 ...