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. 图像Image类、打印Printing相关

    一.Images 1.概述 Image 类为Bitmap(位图) 和 Metafile(矢量图) 的类提供功能的抽象基类.Image类不能直接创建对象的,但Image.FromFile()返回的是Bi ...

  2. tp5.1下redis配置和使用

    //1.config目录下新建redis.php <?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/12/1 ...

  3. 基于 Go 的可嵌入脚本语言 zygomys

    zygomys zygomys 是一种可嵌入的脚本语言. 它是一个具有面向对象风格的现代化 Lisp,提供了一个解释器和 REPL(Read-Eval-Print-Loop:也就是说,它带有一个命令行 ...

  4. Java8-Concurrency

    import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; public class Concurrency1 { pu ...

  5. python自动华 (五)

    Python自动化 [第五篇]:Python基础-常用模块 目录 模块介绍 time和datetime模块 random os sys shutil json和pickle shelve xml处理 ...

  6. Windows服务操作

    资料 https://docs.microsoft.com/zh-cn/dotnet/api/system.serviceprocess.servicecontroller?redirectedfro ...

  7. contos7上安装rabbitmq

    #centeros7 安装erlang yum install erlang #启动扩展源 yum install epel-release #下载rabbitmq源文件 wget http://ww ...

  8. Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description: You play your favourite game yet another time. You chose the character you didn ...

  9. day42_Oracle学习笔记_01

    一.Oracle Database 的基本概念 1.1.一个Oracle服务器 详解如下: 一个Oracle服务器是一个关系型数据管理系统(RDBMS),它提供开放的,全面的,近乎完整的信息管理.   ...

  10. 005_linuxC++之_指针的引入

    (一)直接看代码 #include <iostream> using namespace std; int add(int a){ a = a + ; return a; } int ad ...