[多重集组合数] 计数dp Ant Counting POJ - 3046 白书习题 //(题解推导公式未补完)

poj.org/problem?id=3046

题意:

给出T种数字(蚂蚁)//同数字 同种类 统计时 1 1 2 和 1 2 1 是一样的

每种各有N[i]个 然后用这些数字构成一些序列, 长度在S 到 B 内 组合总数

直接上白书 的多重集组合数 除了用滚动数组减内存

其实我觉得这题比较难理解 书上那个公式具体怎么算的了

dp[ i + 1 ][ j ] =dp[ i + 1 ][ j - 1] + dp[ i ][ j ] - dp[ i ][ j - 1 -ai ]

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <list> 
using namespace std;
typedef long long ll;

const int maxn = 1000+5 ;
const int maxv = 100*1000+5;
const int mod = 1000000 ;
const int INF = 0x3f3f3f3f;
const double PI=acos(-1.0);

int dp[2][maxv];
int used[maxn];

int main(){
	std::ios::sync_with_stdio(false);
	int T,A,S,B,x,ans=0;
	cin>>T>>A>>S>>B;
	for(int i=1;i<=A;i++){
		cin>>x;
		used[x]++;
	}
	dp[0][0]=dp[1][0]=1;
	for(int i=1;i<=T;i++)
		for(int j=1;j<=B;j++)
			if(j-used[i]-1>=0)dp[i%2][j]=(dp[(i-1)%2][j]+dp[i%2][j-1]-dp[(i-1)%2][j-used[i]-1]+mod)%mod;
			else dp[i%2][j]=(dp[(i-1)%2][j]+dp[i%2][j-1])%mod;
	for(int i=S;i<=B;i++)
		ans=(ans+dp[T%2][i])%mod;
	cout<<ans<<endl;
	return 0;
} 

之后补上那个 公式 怎么推导 

未更完

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值