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.

Sample test(s)
input
  1. 4 6
output
  1. 2
input
  1. 9 7
output
  1. 6
input
  1. 1 1
output
  1. 2
Note

The image in the problem statement shows all possible red-green towers for the first sample.

其实就是sb背包dp

因为数组开的小了还wa了一次

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<deque>
  9. #include<set>
  10. #include<map>
  11. #include<ctime>
  12. #define LL long long
  13. #define inf 0x7ffffff
  14. #define pa pair<int,int>
  15. #define pi 3.1415926535897932384626433832795028841971
  16. #define mod 1000000007
  17. using namespace std;
  18. inline LL read()
  19. {
  20. LL x=,f=;char ch=getchar();
  21. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  22. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  23. return x*f;
  24. }
  25. LL a,b,h,ans;
  26. LL f[];
  27. int main()
  28. {
  29. a=read();b=read();
  30. for(int i=;i<=;i++)
  31. if (i*(i+)/<=a+b)h=i;
  32. f[]=;
  33. for (int i=;i<=h;i++)
  34. {
  35. LL sum=i*(i+)/;
  36. for (int j=b;j>=i;j--)
  37. if (sum-j<=a)f[j]=(f[j]+f[j-i])%mod;
  38. }
  39. for (int i=;i<=b;i++)
  40. if (h*(h+)/-i<=a)ans=(ans+f[i])%mod;
  41. printf("%lld\n",ans);
  42. }

cf478D

cf478D Red-Green Towers的更多相关文章

  1. dp --- hdu 4939 : Stupid Tower Defense

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  2. hdu4939 Stupid Tower Defense (DP)

    2014多校7 第二水的题 4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131 ...

  3. Stupid Tower Defense

    Problem Description FSF is addicted to a stupid tower defense game. The goal of tower defense games ...

  4. HDU4939Stupid Tower Defense (有思想的dp)

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...

  5. Video for Linux Two API Specification Revision 2.6.32【转】

    转自:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html Video for ...

  6. Video for Linux Two API Specification revision0.24【转】

    转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification ...

  7. hdu 4939 2014 Multi-University Training Contest 7 1005

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  8. Overview over available Turtle and Screen methods

    24.5.2.1. Turtle methods Turtle motion Move and draw forward() | fd() backward() | bk() | back() rig ...

  9. 理解CSS边框border

    前面的话   边框是CSS盒模型属性中默默无闻的一个普通属性,CSS3的到来,但得边框属性重新焕发了光彩.本文将详细介绍CSS边框 基础样式   边框是一条以空格分隔的集合样式,包括边框粗细(边框宽度 ...

  10. web前端基础知识

    #HTML    什么是HTML,和他ML...    网页可以比作一个装修好了的,可以娶媳妇的房子.    房子分为:毛坯房,精装修    毛坯房的修建: 砖,瓦,水泥,石头,石子....    精 ...

随机推荐

  1. 匹配“is outside location”

    <pre name="code" class="html">is outside location 怎么匹配? . 匹配除换行外的所有单个字符,通常 ...

  2. sql server数据建表

    use edudbgoif exists(select * from sysobjects where name='department')drop table departmentcreate ta ...

  3. 【转】用Device tree overlay掌控Beaglebone Black的硬件资源

    原文网址:https://techfantastic.wordpress.com/2013/11/15/beaglebone-black-device-tree-overlay/ 经过一晚上的Goog ...

  4. Deploy a Sharded Cluster

    Start the Config Server Database Instances for example :  mongod --configsvr --dbpath <path> - ...

  5. Find Successor & Predecessor in BST

    First, we use recursive way. Successor public class Solution { public TreeNode inorderSuccessor(Tree ...

  6. Linux配置FTP服务器

    基于CentOS-6.5 1.先查看是否已安装:rpm -qa vsftpd 或 rpm -ql vsftpd 2.安装:yum install vsftpd -y 3.设置开机启动: chkconf ...

  7. poj 2229 Sumsets(dp 或 数学)

    Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...

  8. Thinkphp交友手机首页简明前台、后台

    先来说下后台吧,后台要写后台模板-V,后台控制器-C 后台模板如下代码: <!DOCTYPE html> <html> <head> <meta charse ...

  9. [Hapi.js] Request Validation with Joi

    hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...

  10. TreeView中右击直接获取节点的方法

    在TreeView中无法直接右击得到一个节点,因为当你选中其中一个右击时(不能是第一个)他会默认跳到第一个. 有时我们要想直接右击得到选中的节点,又时我们又想选中直接右击跳出一个快捷菜单怎么办了! 在 ...