POJ 3406 Ant Counting

题意:T个家族的蚂蚁一共有A只,每个家族的蚂蚁编号分别为1,2...T,这些蚂蚁中的若干个组成一群去觅食,问这一群蚂蚁的数量在s到b之间的方案数一共有多少。


分析:设f[i][j]为前i种蚂蚁一共j只组成的方案数。则f[i][j]=sigma(f[i-1][j-0],f[i-1][j-1]...f[i-1][j-g[i]])。g[i]指编号为i种类的蚂蚁的数量。滚动数组以节约空间。


Code:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define eps 1e-7
#define LL long long
#define pb push_back
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;

const int MOD=1000000;
const int inf=0x3f3f3f3f;
const int maxn=1005;
int sum[2][maxn*10];
int f[maxn];
int t,s,b,a;

int main()
{
    int x;
    scanf("%d %d %d %d",&t,&a,&s,&b);
    memset(f,0,sizeof(f));
    for(int i=0;i<a;i++){
        scanf("%d",&x);
        f[x]++;
    }
    memset(sum,0,sizeof(sum));
    for(int i=0;i<=f[1];i++){
        sum[0][i]=1;
    }
    int cur=1,pre=0;
    for(int i=2;i<=t;i++){
        for(int j=0;j<=a;j++){
            for(int k=0;k<=f[i];k++){
                if(k>j) break;
                sum[cur][j]=(sum[cur][j]+sum[pre][j-k])%MOD;
            }
        }
        cur^=1;pre^=1;
        memset(sum[cur],0,sizeof(sum[cur]));
    }
    cur^=1;
    int ans=0;
    for(int i=s;i<=b;i++) ans=(ans+sum[cur][i])%MOD;
    printf("%d\n",ans);
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值