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

uva1451 - Average 单调队列维护下凸曲线 A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the number of Cs and Gs of the sequence divided by the length of the sequence. GC-ratio is important in gene 阅读详情

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
4 6
Output
2
Input
9 7
Output
6
Input
1 1
Output
2

  给你红色和绿色方块的个数,一层只能放一种颜色,问在堆最高层的情况下有多少种堆法。

  首先根据方块总数算出最高层数h。dp[i][j]表示堆到第i层用j个红方块的堆放种数,但是二维开不下,用滚动数组。最后答案就是dp[h][i]的和,i是堆到最高层红方块的个数范围。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define eps 1e-9
#define INF 0x3f3f3f3f
#define MAXN 200010
#define MAXM 55
#define MAXNODE 100010*4
#define MOD 1000000007
typedef long long LL;
using namespace std;
int R,G;
LL dp[MAXN];
int main(){
    //freopen("in.txt","r",stdin);
    while(scanf("%d%d",&R,&G)!=EOF){
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        LL h=0,cnt=0;
        for(int i=1;;i++){
            cnt+=i;
            if(cnt>R+G) break;
            h=i;
        }
        for(int i=1;i<=h;i++)
            for(int j=R;j>=i;j--) dp[j]=(dp[j]+dp[j-i])%MOD;
        LL sum=h*(h+1)/2,ans=0;
        if(sum-G<0) sum=0;
        else sum-=G;
        for(int i=sum;i<=R;i++) ans=(ans+dp[i])%MOD;
        printf("%I64d\n",ans);
    }
    return 0;
}



uva10237 - Bishops 互不攻击的象 Problem B Bishops Input: standard input Output: standard output Time Limit: 4 seconds Memory Limit: 32 MB   A bishop is a piece used in thegame of chess which is played on a board of squa 阅读详情

相关推荐

TP4056锂电池充电电路设计原理与工程实践

锂离子电池充电管理是嵌入式电源系统的核心基础技术,其本质是通过恒流恒压(CC/CV)控制策略,匹配电池电化学特性以实现安全、高效、长寿命充放电。TP4056作为典型线性充电IC,以精简外围实现预充、恒流、恒压及自动截止全周期管理,但受限于线性拓扑的热耗散特性,必须协同散热设计、电阻精度选型与PCB布局进行系统级优化。该方案广泛应用于STM32智能小车、便携传感器节点等3.7V单节锂电供电场景,兼顾成本、可靠性与工程可实施性,是入门嵌入式硬件电源设计的关键实践范例。

weixin_36064575的博客 234

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

题目链接 01背包计算方案数 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+100,mod=1e9+7; void add(ll &a,ll b){ a=(a+b+mod)%mod; } int main(){ ll h,s,g,r,dp[N],an...

qq_42835440的博客 328

LabView实现modbus通讯

labview实现modbus通讯

Lrj的博客 7676

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

链接: http://codeforces.com/problemset/problem/478/D 题意: 给出r个红砖,g个绿砖,问有多少种方法搭成最高的塔。 题解: 举红色球的层数,当第i层为红色是,i层上面有[0,r]个 红色的,可推出dp[i+j]=dp[i+j]+dp[j],最后 再统计红色的个数就行了,红色最少为max(h*(h+1)/2-g,0)。 代码: ...

花海 220

别再只用线性回归了!用sklearn的核岭回归搞定非线性数据(附RBF核调参实战)

本文详细介绍了如何使用sklearn的核岭回归处理非线性数据,特别是RBF核的应用与调参实战。通过网格搜索找到最佳参数组合,核岭回归能有效捕捉数据中的复杂波动,显著提升模型性能。适合需要解决非线性问题的数据科学家和机器学习工程师。

weixin_34246529的博客 342

Cursor插件安装CodeX保姆级教程:从登录到调整面板布局,一步不落

本文提供Cursor编辑器安装CodeX插件的详细教程,涵盖从登录到调整面板布局的全流程。通过优化界面布局和配置参数,帮助开发者提升编码效率,特别适合需要智能代码补全的编程场景。

weixin_42648844的博客 4834

Codeforces Round #273 (Div. 2) D. Red-Green Towers dp+滚动数组

DRed-Green Towers 题意:有红绿两色的方块,数量分别为r个和g个。有0<=r,g<=2e5,r+g>=1,我们想用这红绿两色的方块(不一定全部,可以是一部分),构成一个高度尽可能高的积木块。 这个积木块需要满足—— 假设高度为h,那么第一层有1个,第二层有2个,……,第h层有h个。 每层方块的颜色,不是全部为红色,就是全部为绿色。 让你输出,有多少种方案...

Pikachu的博客 259

数据服务:数据服务框架Magic-API 介绍及实践

接口快速开发框架 基于Java的接口快速开发框架,编写接口将通过magic-api提供的UI界面完成,自动映射为HTTP接口,无需定义Controller、Service、Dao、Mapper、XML、VO等Java对象即可完成常见的HTTP API接口开发 。在线页面快速开发平台 基于 vue 的在线页面快速开发平台,主要把所有的 vue 代码都改为在线配置,最终获得一个 json 格式的页面新一代爬虫平台 基于Java实现的新一代爬虫平台,以图形化方式定义爬虫流程,不写代码即可完成爬虫。今天给大家安利一

GIS摆渡人 2076

Codeforces Round #273 (Div. 2) D. Red-Green Towers 背包dp

D. Red-Green Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There arerred andggreen blocks fo...

weixin_30325793的博客 253

SO_KEEPALIVE、TCP_KEEPIDLE、TCP_KEEPINTVL、保活包

是一个套接字选项,用于设置是否启用 keepalive 机制。在这段代码中没有涉及到选项的设置。当被设置为非零值时,表示启用 keepalive 机制。keepalive 是一种用于检测连接是否仍然有效的机制。通过定期发送一些特定的探测数据,可以检测到网络连接的异常中断或对端应用程序的崩溃退出。为了避免以上情况,可以启用 keepalive 机制,即使在无数据传输的情况下也定期发送探测数据。如果在一定时间内没有收到对端的响应,就认为连接已经失效,并进行相应的处理。要启用选项,需要使用函数。其中,fd。

m0_46376834的博客 4824

基于TKVA与深度学习的量子点微型光谱仪光谱重建改进算法研究

本文提出了一种融合深度学习的改进TKVA算法(TKVA-DL),用于提升量子点微型光谱仪的光谱重建精度。该方法创新性地结合深度先验网络与注意力机制,通过自适应学习光谱隐式先验替代传统固定正则化项,并动态加权探测器响应通道。实验表明,所提方法在仿真和实测数据上均显著优于传统TKVA及主流深度学习算法,RMSE降低35%,PSNR提升4.2 dB,同时保持物理可解释性。完整MATLAB实现验证了方法的有效性与可复现性,为微型光谱仪的高精度重建提供了新思路。 关键词:量子点微型光谱仪;光谱重建;Tikhonov正

AI的内部世界的博客 88

Codeforces Round #273 (Div. 2)D. Red-Green Towers(背包)

题目链接题目描述: D. Red-Green Towers time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are r red and g green blocks for construction of the

fouzhe的博客 615

【DRAM存储器二十六】DDR4介绍-DDR4 SDRAM的主要技术特性之CA Parity、CRC Write date

详述DDR4的CA奇偶检验和写数据CRC校验功能

highman110的博客 1315

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

D. Red-Green Towers There arerred andggreen blocks for construction of thered-greentower.Red-greentower can be built following next rules: Red-green tower is consis...

weixin_30750335的博客 284

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces Round #273 (Div. 2) D. Red-Green Towers(DP+滚动数组优化)

题目链接 题意:有两种颜色的积木 向上垒,每层只能是同一种颜色,且每层的个数等于层数。问有多少种垒法。 思路:dp【i】【j】代表前i层用了j个红块的方案数,由于数很大,需要用滚动数组优化。 ...

qq_42479630的博客 189

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

D. Red-Green Towers(Codeforces Round #273)

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

ACway的专栏 2219

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

【Codeforces Round 273 (Div 2)D】【DP 滚动数组】 Red-Green Towers 两种颜色积木拼搭最高锯齿楼每层颜色相同的总方案数

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

snowy_smile的博客 2185

Codeforces Round #273 (Div. 2)

联系:http://codeforces.com/contest/478 A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes There are five people playing a game called "...

weixin_33690963的博客 81

Codeforces 8VC Venture Cup 2016 - Elimination Round解题报告

实际上苟蒻只会做四题。。 A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Calvin the ro

CRZbulabula的博客 1452

求区间这种数的个数,这个数恰好等于k个互不相等的2的整数次幂之和 数位统计

Description 给定一个区间[x,y],求这个区间中满足下列条件的整数的个数:这个数恰好等于k个互不相等的2的整数次幂之和。例如x=15,y=20,k=2.则有且仅有下列三个数满足题意: 17=2^4+2^0; 18=2^4+2^1; 20=2^4+2^2;   (a^b代表是a的b次方) Input 接下来输入T行,每行对应一个样例,每行有3个整数x, y

1613

数位DP的记忆化搜索形式

数位DP的记忆化搜索形式比一般递推形式好写多了,而且一般不容易出错。   dfs求[0,n]有多少个符合的,先把n换成字符串形式。   cur:现在处理到哪一位。   s:搜索到目前为止,之前的状态,具体什么状态看情况而定。   e:是否到达边界,如果没到这一位只取到9,否则只能取到bit[cur]。   z:前导0标记,也就是是否前面的都是0,有些情况需要特殊判断。   一般情况

1386

uva11481 - Arrange the Numbers N个数前M个错排

Consider this sequence {1, 2, 3, … , N}, as a initial sequence of firstN natural numbers. You can rearrange this sequence in many ways. Therewill be N! different arrangements. You have to calculate t

1161

字符串DP

这几天在做DP,总结一下,先是字符串这一类的。   最简单的就是给你两个字符串a和b,让你求最长公共子序列(LCS)。用dp[i][j]作为第一个字符串匹配到i位置和第二个字符串匹配到j位置时的最长公共子序列,所以如果a[i]==b[j],dp[i][j]=dp[i-1][j-1]+1,否则dp[i][j]=max(dp[i-1][j],dp[i][j-1])。   之后一些题就和是这个的变形

1124
上一篇: zoj3822 Domination 牡丹江现场赛D题 概率DP
下一篇: 后缀数组
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值