【POJ - 3046】Ant Counting(多重集组合数)
Ant Counting
直接翻译了
Descriptions
贝西有T种蚂蚁共A只,每种蚂蚁有Ni只,同种蚂蚁不能区分,不同种蚂蚁可以区分,记Sum_i为i只蚂蚁构成不同的集合的方案数,问Sum_k(S≤k≤B)之和。Input第一行4个整数T、A、S、B。 接下来A行,每行一个整数,代表这只蚂蚁的种类。Output输出Sum_k(S≤k≤B)之和。 (数据范围见原文)
Sample Input
3 5 2 3
1
2
2
1
3
Sample Output
10
题目链接
https://vjudge.net/problem/POJ-3046
白书69页

参考我学长的博客
https://blog.csdn.net/a1097304791/article/details/90371914
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100005
using namespace std;
int T,A,S,B;
int dp[][Maxn];
int c[Maxn];
int M=;//对M取余
int main()
{
cin>>T>>A>>S>>B;
for(int i=;i<A;i++)
{
int x;
cin>>x;
c[x]++;
}
for(int i=;i<=T;i++)
dp[i][]=;
for(int i=;i<=T;i++)
{
for(int j=;j<=A;j++)
{
if(j--c[i]>=)
dp[i][j]=(dp[i][j-]+dp[i-][j]-dp[i-][j--c[i]]+M)%M;
else
dp[i][j]=(dp[i][j-]+dp[i-][j]+M)%M;
}
}
int ans=;
for(int i=S;i<=B;i++)
ans=(ans+dp[T][i]+M)%M;
cout<<ans<<endl;
return ;
}
【POJ - 3046】Ant Counting(多重集组合数)的更多相关文章
- POJ 3046 Ant Counting ( 多重集组合数 && 经典DP )
题意 : 有 n 种蚂蚁,第 i 种蚂蚁有ai个,一共有 A 个蚂蚁.不同类别的蚂蚁可以相互区分,但同种类别的蚂蚁不能相互区别.从这些蚂蚁中分别取出S,S+1...B个,一共有多少种取法. 分析 : ...
- poj 3046 Ant Counting(多重集组合数)
Ant Counting Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total ...
- poj3046 Ant Counting——多重集组合数
题目:http://poj.org/problem?id=3046 就是多重集组合数(分组背包优化): 从式子角度考虑:(干脆看这篇博客) https://blog.csdn.net/viphong/ ...
- poj 3046 Ant Counting
Ant Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4982 Accepted: 1896 Desc ...
- 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
大致题意:给你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_(动态规划,多重集组合数)
描述 http://poj.org/problem?id=3046 n种蚂蚁,第i种有ai个,不同种类的蚂蚁可以相互区分,但同一种类的蚂蚁不能相互区分,从这些蚂蚁中取出s,s+1,s+2,...,b- ...
随机推荐
- 六、vue基础--过滤器定义
七.过滤器定义 1.使用:{{username|strip}}.<a :href="url|strip">百度</a> 2.定义:都是定义一个函数,这个函数 ...
- 「数据结构与算法(Python)」(二)
顺序表 在程序中,经常需要将一组(通常是同为某个类型的)数据元素作为整体管理和使用,需要创建这种元素组,用变量记录它们,传进传出函数等.一组数据中包含的元素个数可能发生变化(可以增加或删除元素). 对 ...
- 第六章 Flask数据库(一)之SQLAlchemy
将ORM模型映射到数据库中 1. 用`declarative_base`根据`engine`创建一个ORM基类. from sqlalchemy.ext.declarative import decl ...
- 2019牛客多校B generator 1——十进制快速幂
题目 已知 $x_i = ax_i + bx_{i-1}$,求 $x_n \% MOD$.($1\leq n\leq 10^{(10^6)}$) 分析 写成矩阵快速幂的形式,相当于求转移矩阵的 $n$ ...
- 快捷键IntelliJ IDEA For Mac
http://www.cnblogs.com/wxd0108/p/5295017.html Mac键盘符号和修饰键说明 ⌘ Command ⇧ Shift ⌥ Option ⌃ Control ↩︎ ...
- Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置(转)
用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...
- CF1156E Special Segments of Permutation
思路:笛卡尔树?(好像并不一定要建出来,但是可以更好理解) 提交:2次 错因:没有判左右儿子是否为空来回溯导致它T了 题解: 建出笛卡尔树,考虑如何计算答案: 先预处理每一个值出现的位置 \(pos[ ...
- 配置文件的属性ENC加密
转载:https://www.cnblogs.com/zqyx/p/9687136.html 在micro service体系中,有了config server,我们可以把配置存放在git.svn.数 ...
- 034_非交互自动生成 SSH 密钥文件
#!/bin/bash#-t 指定 SSH 密钥的算法为 RSA 算法;-N 设置密钥的密码为空;-f 指定生成的密钥文件存放在哪里 rm -rf ~/.ssh/{known_hosts,id_rsa ...
- AOP 底层实现原理
1.核心业务接口与实现 public interface IManager { void add(String item); } public class IManagerImpl implement ...