cf478D Red-Green Towers
来源:互联网 发布:sql数据库价格 编辑:程序博客网 时间:2024/04/29 16:34
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.
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 the only integer — the number of different possible red-green towers of height h modulo 109 + 7.
4 6
2
9 7
6
1 1
2
The image in the problem statement shows all possible red-green towers for the first sample.
其实就是sb背包dp
因为数组开的小了还wa了一次
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<deque>#include<set>#include<map>#include<ctime>#define LL long long#define inf 0x7ffffff#define pa pair<int,int>#define pi 3.1415926535897932384626433832795028841971#define mod 1000000007using namespace std;inline LL read(){ LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}LL a,b,h,ans;LL f[1000010];int main(){a=read();b=read();for(int i=1;i<=1000;i++) if (i*(i+1)/2<=a+b)h=i;f[0]=1;for (int i=1;i<=h;i++){ LL sum=i*(i+1)/2; for (int j=b;j>=i;j--)if (sum-j<=a)f[j]=(f[j]+f[j-i])%mod;}for (int i=0;i<=b;i++) if (h*(h+1)/2-i<=a)ans=(ans+f[i])%mod;printf("%lld\n",ans);}
- cf478D Red-Green Towers
- codeforce 之 Red-Green Towers
- codeforces D - Red-Green Towers
- 【CODEFORCES】 D. Red-Green Towers
- D - Red-Green Towers dp
- D. Red-Green Towers(Codeforces Round #273)
- Codeforces 478D Red-Green Towers dp
- codeforces 478D Red-Green Towers dp
- codeforces 478D Red-Green Towers (dp)
- Codeforces 478D Red-Green Towers (DP)
- Codeforces 478D Red-Green Towers (DP)
- cf#273-D. Red-Green Towers-dp
- CodeForces 478D-Red-Green Towers
- CF 478D - Red-Green Towers(DP)
- codeforces 478D Red-Green Towers(dp)
- Codeforces Round #273 (Div. 2) D. Red-Green Towers
- Codeforces Round #273 (Div. 2) D. Red-Green Towers
- codeforces 478D D. Red-Green Towers(dp)
- Cocos2d-x_CCControlSwitch(开关类)介绍
- maven 配置篇 之pom.xml
- C++ 60分钟入门教程 - 5、C++引用
- 程序员生存定律:打造属于自己的稀缺性
- 姿转纵仔孜拙缀庄资装坐邹酌椎仔驻资钻
- cf478D Red-Green Towers
- git 指令整理
- iOS8中的UIScreen、UIWindow、键盘尺寸、状态栏尺寸的改动
- 组砖嘴椎最子尊爪阻足宗桩揍综撰赘尊钻
- 公司实习不到两周的总结and感想
- 卓诅转抓踪转诅灼总尊专钻诅嘴浊琢纵钻
- 宗纂坠拙邹作卓注椎祖族卓纵着锥驻着座
- 将一个表中个某一列修改为自动增长的方法
- 拙子足籽赘装作坐做滋桩坠足追踪族族作