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(多重集组合数)的更多相关文章

  1. POJ 3046 Ant Counting ( 多重集组合数 && 经典DP )

    题意 : 有 n 种蚂蚁,第 i 种蚂蚁有ai个,一共有 A 个蚂蚁.不同类别的蚂蚁可以相互区分,但同种类别的蚂蚁不能相互区别.从这些蚂蚁中分别取出S,S+1...B个,一共有多少种取法. 分析 :  ...

  2. poj 3046 Ant Counting(多重集组合数)

    Ant Counting Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total ...

  3. poj3046 Ant Counting——多重集组合数

    题目:http://poj.org/problem?id=3046 就是多重集组合数(分组背包优化): 从式子角度考虑:(干脆看这篇博客) https://blog.csdn.net/viphong/ ...

  4. poj 3046 Ant Counting

    Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4982   Accepted: 1896 Desc ...

  5. poj 3046 Ant Counting (DP多重背包变形)

    题目:http://poj.org/problem?id=3046 思路: dp [i] [j] :=前i种 构成个数为j的方法数. #include <cstdio> #include ...

  6. poj 3046 Ant Counting——多重集合的背包

    题目:http://poj.org/problem?id=3046 多重集合的背包问题. 1.式子:考虑dp[ i ][ j ]能从dp[ i-1 ][ k ](max(0 , j - c[ i ] ...

  7. POJ 3046 Ant Counting DP

    大致题意:给你a个数字,这些数字范围是1到t,每种数字最多100个,求问你这些a个数字进行组合(不包含重复),长度为s到b的集合一共有多少个. 思路:d[i][j]——前i种数字组成长度为j的集合有多 ...

  8. POJ 3046 Ant Counting(递推,和号优化)

    计数类的问题,要求不重复,把每种物品单独考虑. 将和号递推可以把转移优化O(1). f[i = 第i种物品][j = 总数量为j] = 方案数 f[i][j] = sigma{f[i-1][j-k], ...

  9. POJ_3046_Ant_Counting_(动态规划,多重集组合数)

    描述 http://poj.org/problem?id=3046 n种蚂蚁,第i种有ai个,不同种类的蚂蚁可以相互区分,但同一种类的蚂蚁不能相互区分,从这些蚂蚁中取出s,s+1,s+2,...,b- ...

随机推荐

  1. 部署logstash节点

    .部署Logstash节点 1.查看系统环境: [root@Logstash ~]# hostname Logstash [root@Logstash ~]# cat /etc/redhat-rele ...

  2. python_字符串方法

    1.字符串大小写转 value = "wangdianchao" # 转换为大写 big_value = value.upper() print(big_value) # 转换为小 ...

  3. hexo主题next 7.X版本配置美化

    我们主要对next主题进行了如下配置操作.效果可以前往https://www.ipyker.com 查看. 也可以前往https://github.com/ipyker/hexo-next-theme ...

  4. Mysql中对字符串类型的字段进行数字值排序

    排序字段+0或者*1,类似  Java 把 其他类型转换成字符串 比如 +“”: 一.对普通数字字符串字段排序 -- 方式一 SELECT * FROM xxxxxx WHERE STATUS ' O ...

  5. Python中的字典分组函数(groupby,itertools)

    from operator import itemgetter # itemgetter用来去dict中的key,省去了使用lambda函数 from itertools import groupby ...

  6. http响应Last-Modified和ETag

    http响应Last-Modified和ETag [日期:2008-06-16] 来源:  作者: [字体:大 中 小] 基础知识 1) 什么是”Last-Modified”? 在浏览器第一次请求某一 ...

  7. MySQL之text字段

    TEXT类型一般分为 TINYTEXT(255长度).TEXT(65535). MEDIUMTEXT(int最大值16M),和LONGTEXT(long最大值4G)这四种,它被用来存储非二进制字符集, ...

  8. Java8-Lambda-No.01

    import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util ...

  9. 边学边体验django--模型

    步骤: 1.选定数据库,然后修改 settings.py 中的 DATABASES配置 实验过了sqlite3. 应该是这个样子的: 2. 创建app, 建立数据表模型. python manage. ...

  10. box-orient

    box-orient 语法: box-orient:horizontal | vertical | inline-axis | block-axis 默认值:horizontal 适用于:伸缩盒容器大 ...