D. Red-green Towers time limit/test 2 seconds memory limit per test 256 megabytes input standard input output standard Output
There are r red and G green blocks for construction of the Red-green tower. Red-green Tower can be built following next rules:
Red-green Tower is consisting of some number of levels;
Let the Red-green tower consist of n levels, then the "a" of this tower should consist of n blocks, second level -of n-1 blocks, the third one-of n-2-blocks, and so on-the last level of such tower should consist of the one Block. In a words, each successive level should contain one block less than the previous one;
Each level of the Red-green tower should contain blocks of the same color.
Let H is the maximum possible number of levels of Red-green tower, that can is built out of R red and G green blocks Meeti Ng the rules above. The task is to determine how many different Red-green towers has h levels can be built out of the available.
Two red-green towers are considered different if there exists level, this some of red consists in the one blocks and Consists of green blocks in the other tower.
You are are to write a program that'll find the number of different red-green towers of height H modulo 109 + 7. Input
The only line of input contains two integers r and G, separated by a single space-the number of available red and green Blocks respectively (0≤r, G≤2 105, R + g≥1). Output
Output the only integer-the number of different possible red-green towers of height H modulo 109 + 7. Sample Test (s) input
4 6
Output
2
Input
9 7
Output
6
Input
1 1
Output
2
Note
The image in the problem statement shows all possible red-green for the "the"
DP, my code is to enumerate the layers of the red ball, when the layer I is red is, the I layer above has [0,r] a red, may launch the DP[I+J]=DP[I+J]+DP[J], finally
then count the number of red, and the red is at least Max (h* (h+1)/2-g,0).
Code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int mod=1000000000+7;
Long long dp[500000];
int main ()
{
int r,g;
scanf ("%d%d", &r,&g);
int temp=r+g;
int h=sqrt (temp*2);
while (h* (h+1)/2>temp)
h--;
Dp[0]=1;
for (int i=1;i<=h;i++)
{for
(int j=r;j>=0;j--)
{
dp[i+j]= (dp[i+j]+dp[j])%mod;
}
long long ans=0;
for (int I=max (h* (h+1)/2-g,0); i<=r;i++) ans=
(ans+dp[i))%mod;
printf ("%i64d\n", ans);
return 0;
}