题意:T种蚂蚁,共计A只,种内没有区别,问含有x只蚂蚁的子集有多少种(x∈[S,B])
题解:动态规划,dp[i][j]代表用前i种蚂蚁凑成j只蚂蚁的集合的方法数,由于T*A太大,用滚动数组实现,最后输出的是答案mod 1000000
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#define SCAND(x) scanf("%d",&(x))
#define SCANS(x) scanf("%s",(x))
#define PRINTD(x) printf("%d",(x))
using namespace std;
const int INF=1<<30;
int num[1111];
int dp[2][111111];
const int MOD=1000000;
int main()
{
#ifndef ONLINE_JUDGE
freopen("H:/in.txt","r",stdin);
//freopen("H:/out.txt","w",stdout);
#endif
int T,m,s,b;
//cin>>T>>m>>s>>b;
scanf("%d%d%d%d",&T,&m,&s,&b);
int tmp;
for(int i=0;i<m;i++)
{
scanf("%d",&tmp);
num[tmp]++;
}
int sum=0;
//dp[0][0]=1;
for(int i=1;i<=T;i++)
{
int y=i&1;
int x=y^1;
//dp[y][1]=i;
memcpy(dp[y],dp[x],sizeof(dp[x]));
for(int j=0;j<=sum&&j<=b;j++)
for(int k=1;k<=num[i];k++)
{
if(j==0)
dp[y][j+k]+=1;
else
{
dp[y][j+k]+=dp[x][j],dp[y][j+k]%=MOD;
}
}
sum+=num[i];
}
int y=T&1;
int ans=0;
for(int i=s;i<=b;i++)
{
ans+=dp[y][i],ans%=MOD;
}
printf("%d\n",ans);
}