题意 : 有 n 种蚂蚁,第 i 种蚂蚁有ai个,一共有 A 个蚂蚁.不同类别的蚂蚁可以相互区分,但同种类别的蚂蚁不能相互区别.从这些蚂蚁中分别取出S,S+1...B个,一共有多少种取法. 分析 :  实际就是要解决 => 从 n 种物品中取出 m 个有多少种取法 ( 同种无法区分 ) 计数问题的 DP 定义必须保证不重复计数 这里定义 dp[i+1][j] => 从前 i 种物品中取出 j 个的组合数 根据定义为了从前 i 种物品中取出 j 个,可以从前 i-1 中取出 j-k 个并从 i…
Ant Counting Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 2 Problem Description Bessie was poking around the ant hill one day watching the ants march to and fro w…
Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4982   Accepted: 1896 Description Bessie was poking around the ant hill one day watching the ants march to and fro while gathering food. She realized that many of the ants were…
题目:http://poj.org/problem?id=3046 就是多重集组合数(分组背包优化): 从式子角度考虑:(干脆看这篇博客) https://blog.csdn.net/viphong/article/details/48110525 从意义的角度来考虑: 当 j<=a[i] 时,f[i][j] = f[i-1][j]  + f[i][j-1],就是分成了不选第 i 种物品和至少选一个第 i 种物品的情况,其中 f[i][j-1] 代表 j-1 后剩下的那一个物品一定是第 i 种:…
题目:http://poj.org/problem?id=3046 思路: dp [i] [j] :=前i种 构成个数为j的方法数. #include <cstdio> #include <cstring> #include <iostream> int T,A,S,B; int hash[1010]; int dp[1010][10100]; const int MOD=1e6; using namespace std; int main(){ while(cin&g…
大致题意:给你a个数字,这些数字范围是1到t,每种数字最多100个,求问你这些a个数字进行组合(不包含重复),长度为s到b的集合一共有多少个. 思路:d[i][j]——前i种数字组成长度为j的集合有多少个. 那么,当前考虑第i种数字,我要组成长度为j的集合,只用在前i-1种数字所组成的集合中,只要添加0...cnt[i]个第i种数字之后长度能够达到j的那些集合数加起来 所以方程可以写成d[i][j] = ∑(cnt[i],0)  d[i-1][j-k]. 每种数字最多100个,数字最大为1000…
题目:http://poj.org/problem?id=3046 多重集合的背包问题. 1.式子:考虑dp[ i ][ j ]能从dp[ i-1 ][ k ](max(0 , j - c[ i ] ) <= k <= j)转移来. 对于j<=c[ i ],这就是前缀和一样,所以dp[ i ][ j ] = dp[ i ][ j-1 ] + dp[ i-1 ][ j ]: 对于j>c[ i ],加了dp[ i ][ j-1 ] + dp[ i-1 ][ j ]之后会多加了一项dp[…
计数类的问题,要求不重复,把每种物品单独考虑. 将和号递推可以把转移优化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<iost…
Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17168   Accepted: 9270 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each villa…
#include <cstdio> #include <iostream> using namespace std; +; +; +; ; int n,m,M; int a[max_n]; int dp[max_M][max_M]; // dp[i][j]:从前i件商品中,选出j个的组合数 void solve() { // 初始化dp数组,无论当前有多少件,一件都不取的方法只有一种哦 ;i<=n;++i) { dp[i][]=; } // 从第一件物品开始取 ;i<=…