题意:有r个红砖块和b个绿砖块,用这些砖块建一个塔,假设塔有h层,则从下往上第i层有h-i+1个同种颜色的砖块。问有多少种方案使塔的高度最高。
解析:塔的最大高度很容易求得。h最大不过700。
设h是塔的最大高度,dp[i][j]为建i层塔用j个红砖块的方案数。
则 dp[i][j] = sigma(dp[k][j])+dp[i-1][j-i] (1<=k<=i-1)
因空间会爆,所以用滚动数组。
[code]:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
const LL MOD = 1e9+7;
const int maxn = 2e5+5;
int n,m,h;
LL dp[maxn];
int main(){
int i,j,d;
scanf("%d%d",&n,&m);
for(h = 0;(h+1)*(h+2)/2<=n+m;h++);
dp[0] = 1;
for(i = 1;i <= h;i++){
for(j = n;j>=i;j--)
dp[j] = (dp[j]+dp[j-i])%MOD;
}
LL ans = 0;
for(i = max(0,h*(h+1)/2-m);i<=n;i++){
ans = (ans + dp[i])%MOD;
}
printf("%I64d\n",ans);
return 0;
}