计数类的问题,要求不重复,把每种物品单独考虑。

将和号递推可以把转移优化O(1)。

f[i = 第i种物品][j = 总数量为j] = 方案数

f[i][j] = sigma{f[i-1][j-k],(k = [0,min(j,c[i])])}
把和号展开 
f[i][j]  :    j-0,j-1,...,j-a[i]
f[i][j-1] :       j-1,j-2,...,j-a[i]-1
中间部分是一样的可以避免重复计算。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std; int T, A, S, B;
const int maxt = 1e3+, maxa = 1e5+, mod = 1e6;
int f[][maxa];
int c[maxt]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
scanf("%d%d%d%d",&T,&A,&S,&B);
for(int i = A; i--;){
int x; scanf("%d",&x);
c[x]++;
}
f[][] = f[][] = ; //不选方案数为1
for(int i = ; i <= T; i++){
int a = i&, b = a^;
for(int j = ; j <= B; j++){
if(j-c[i]>){
f[a][j] = ( f[a][j-] + f[b][j] - f[b][j--c[i]] ) % mod;
}else {
f[a][j] = ( f[a][j-] + f[b][j] ) % mod;
}
}
}
int sum = , *F = f[T&];
for(int i = S; i <= B; i++){
sum = (sum + F[i]) % mod;
}
printf("%d\n",sum<?sum+mod:sum);
return ;
}

POJ 3046 Ant Counting(递推,和号优化)的更多相关文章

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

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

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

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

  3. poj 3046 Ant Counting

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

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

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

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

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

  6. POJ 3046 Ant Counting DP

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

  7. POJ 1664 放苹果 (递推)

    题目链接:http://poj.org/problem?id=1664 dp[i][j]表示i个盘放j个苹果的方案数,dp[i][j] 可以由 dp[i - 1][j] 和 dp[i][j - i] ...

  8. HOJ 2148&POJ 2680(DP递推,加大数运算)

    Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...

  9. POJ 2506 Tiling(递推+大整数加法)

    http://poj.org/problem?id=2506 题意: 思路:递推.a[i]=a[i-1]+2*a[i-2]. 计算的时候是大整数加法.错了好久,忘记考虑1了...晕倒. #includ ...

随机推荐

  1. python的virtualenv环境与使用

    1.安装virtualenv 在安装virtualenv之前,我们需要安装至少有一个版本的Python:因为virtualenv是python的一个第三方模块,必须基于python环境才能安装: 如果 ...

  2. 数据绑定—Source(绑定到静态类的静态属性)

    <UserControl x:Class="绑定.绑定Source" xmlns="http://schemas.microsoft.com/winfx/2006/ ...

  3. 51nod1010(枚举+二分)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 题意:中文题诶- 思路:求第一个比 x (1<= ...

  4. DNS解析工具--nslookup和dig使用

    1.nslookup使用 [root@master ~]# nslookup> server 8.8.8.8    #指定域名服务器Default server: 8.8.8.8Address: ...

  5. iOS拼图

       #import "ViewController.h" @interface ViewController () @end @implementation ViewContro ...

  6. PDO中构建事务处理的应用程序

    <meta http-equiv="Content-Type" content="text/html";charse="utf-8" ...

  7. Chinese Zodiac (水题)

    The Chinese Zodiac, known as Sheng Xiao, is based on a twelve-year cycle, each year in the cycle rel ...

  8. 文件拷贝io nio比较

    import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...

  9. 解决tomcat闪退问题

    https://blog.csdn.net/zh2nd/article/details/79068680 转载此博客链接内容,非常感谢博主 本文参考CSDN博主 哈克沃德.的<Tomcat8启动 ...

  10. placeholder设置默认显示

    <textarea rows="4" cols="50" placeholder="请在此处介绍自己..."> </tex ...