D. Red-Green Towers
time limit per 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 first level 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 other 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 be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.

Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.

You are to write a program that will 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.

Examples
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 towers for the first sample.

题意:有r个红方块,g个绿方块,第i层有i块,每层的方格颜色相同,层数为最多装的层数,求方案数;

思路:得到用i块红方块装这个red-green towers的方案,剩余用绿色装,判断是否够,够就加;

01背包方案数,复杂度(h*min(r,g));

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int h[];
int hh(int x)
{
int pos=upper_bound(h+,h+,x)-h;
return pos-;
}
int v[];
ll dp[N<<];
int main()
{
for(int i=;i<=;i++)
v[i]=i,h[i]=i*(i+)/;
int r,g;
scanf("%d%d",&r,&g);
int hig1=hh(r+g);
memset(dp,,sizeof(dp));
dp[]=;
for(int t=;t<=hig1;t++)
{
for(int i=r;i>=t;i--)
dp[i]+=dp[i-v[t]],dp[i]%=mod;
}
ll ans=;
for(int i=max(,h[hig1]-g);i<=r;i++)
ans+=dp[i],ans%=mod;
printf("%lld\n",ans);
return ;
}

Codeforces Round #273 (Div. 2) D. Red-Green Towers 背包dp的更多相关文章

  1. 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations

    题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...

  2. Codeforces Round #233 (Div. 2) B. Red and Blue Balls

    #include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...

  3. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  4. Codeforces Round #273 (Div. 2)-C. Table Decorations

    http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...

  5. Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心

    A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. codeforces 的 Codeforces Round #273 (Div. 2) --C Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #273 (Div. 2)C. Table Decorations 数学

    C. Table Decorations   You have r red, g green and b blue balloons. To decorate a single table for t ...

  8. Codeforces Round #273 (Div. 2)D. Red-Green Towers DP

    D. Red-Green Towers   There are r red and g green blocks for construction of the red-green tower. Re ...

  9. Codeforces Round #273 (Div. 2)-B. Random Teams

    http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...

随机推荐

  1. python的基础数据类型笔记

    注意:此文章基于python3.0以上做的笔记. python的基础数据类型大体有一下几种 一.int int类型有以下几种方法 .bit_length 返回数据在内存中所占的比特位 如下: prin ...

  2. 练习: 省市联动(Ajax)

    // 示例一: china.xml (位于 src 目录下) <?xml version="1.0" encoding="utf-8"?> < ...

  3. velocity 遍历EventHandler Iterator

    EventHandlerUtil 类的 iterateOverEventHandlers方法 for (Iterator i = handlerIterator; i.hasNext();){ Eve ...

  4. Python3.6全栈开发实例[020]

    20.判断一个数是否是水仙花数, 水仙花数是一个三位数, 三位数的每一位的三次方的和还等于这个数. 那这个数就是一个水仙花数, 例如: 153 = 1**3 + 5**3 + 3**3 num = i ...

  5. 我的Android进阶之旅------>Android中adb install 安装错误常见列表

    adb的安装过程分为传输与安装两步. 在出错后,adb会报告错误信息,但是信息可能只是一个代号,需要自己定位分析出错的原因. 下面是从网上找到的几种常见的错误及解决方法: 1.INSTALL_FAIL ...

  6. (4.11)sql server内存使用

    一些内存使用错误理解   开篇小感悟 在实际的场景中会遇到各种奇怪的问题,为什么会感觉到奇怪,因为没有理论支撑的东西才感觉到奇怪,SQL Server自己管理内存,我们可以干预的方式也很少,所以日常很 ...

  7. ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决(转)

    通过终端安装程序sudo apt-get install xxx时出错: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource t ...

  8. c# 获取网页源代码(支持cookie),最简单代码

    /// /// 获取网页源码 public static string GetHtmls(string url, string referer = "", string cooki ...

  9. checked 和 unchecked 基元类型操作

    对基元类型执行的许多算术运算都可能造成溢出: Byte b = ; b = (Byte) (b + ); // b 现在包含 44(或者十六进制值 2C) 重要提示:执行上述算术运算时,第一步要求所有 ...

  10. django基本安装

    一.web框架 1.什么是web框架? Web框架是一种开发框架,用来支持动态网站.网络应用程序及网络服务的开发.其类型有基于请求的和基于组件的两种框架. 本质上其实就是一个socket服务端,用户的 ...