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. 统计TCP网络连接情况

    #!/bin/bash metric=$1 tmp_file=/tmp/tcp_status.txt /bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a i ...

  2. Python: names, values, assignment and mutability

    推荐先看视频(youtube) Ned Batchelder - Facts and Myths about Python names and values - PyCon 2015 Change v ...

  3. <..................> 哈佛大学哲学系 && 历史哲学笔记文献集

    哈佛大学哲学系课程表            (一)概况    (1)哈佛大学哲学系现有教师21人,其中访问教授7人,教师流动性较大,每年有一定的变化.以下为现任教师:Richard Moran(系主任 ...

  4. IBM WebSphere cannot start in RAD 9.1

    Have solved the problem. Solutions follows Step 1: double click on "WebSphere Application Serve ...

  5. MySQL如何优化GROUP BY :松散索引扫描 VS 紧凑索引扫描

    执行GROUP BY子句的最一般的方法:先扫描整个表,然后创建一个新的临时表,表中每个组的所有行应为连续的,最后使用该临时表来找到组 并应用聚集函数.在某些情况中,MySQL通过访问索引就可以得到结果 ...

  6. hive bin下的进入beeline 命令行和hive有什么不同?

    Hive 0.11中引入的HiveServer2有一个自己的CLI叫Beeline. HiveCLI现在已经过时,与Beeline相比,其缺少多用户.安全和其他与HiveServer2兼容的特性. 从 ...

  7. 阿里云下 centos7下启动程序总是被killed ,看内存占用情况以检查哪些服务存在问题并调整参数作调优

    很久不搭理自己的网站了,几天突然发现启动程序总是被killed, 于是查看了系统日志 vi /var/log/messages 发现出现 kernel: Out of memory: Kill pro ...

  8. PictureBox 双缓冲防止闪屏

    Bitmap bm = new Bitmap(this.pbTraffic.Image); BufferedGraphicsContext current = BufferedGraphicsMana ...

  9. 财经世界(2)A股B股和H股

    在发行过程中,公司通过章程给不同股份形式赋予不同的权益,使公司股份出现A股.B股等形式.我国上市公司的股票有A股.B股.H股.N股.S股等的区分.这一区分的主要依据股票的上市地点和所面对的投资者而定. ...

  10. Git版本控制系统VCS

    Git版本控制系统VCS 一.版本控制系统基本情况说明 版本控制是一种记录一个或者若干个文件内容的变化,以便将来查阅特定版本修订情况的系统 1.作用 记录文件的所有历史变化 随时可回复到任何一个历史状 ...