http://codeforces.com/problemset/problem/478/D

思路:dp:f[i][j]代表当前第i层,用了j个绿色方块的方案数,用滚动数组,还有,数组清零的时候一定要用memset,不然for的常数太大。。

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
const int Mod=;
int n,m,sum[],f[][];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();m=read();
for (int i=;i<=;i++)
sum[i]=sum[i-]+i;
f[][]=;
int i;
for (i=;;i++){
if (sum[i]>n+m) break;
memset(f[i%],,sizeof f[i%]);
for (int j=;j<=sum[i]&&j<=m;j++){
if (sum[i]-j<=n) (f[i%][j]+=f[(i-)%][j])%=Mod;
if (sum[i]-j<=n&&j>=i) (f[i%][j]+=f[(i-)%][j-i])%=Mod;
}
}
int ans=;
for (int j=;j<=m;j++)
ans=(ans+f[(i-)%][j])%Mod;
printf("%d\n",ans);
return ;
}

Codeforces 478D Red-Green Towers的更多相关文章

  1. Codeforces 478D Red-Green Towers:dp

    题目链接:http://codeforces.com/problemset/problem/478/D 题意: 给你r个红方块和g个绿方块,让你用这些方块堆一个塔. 最高层有1个方块,每往下一层块数+ ...

  2. CodeForces 478D Red-Green Towers (DP)

    题意:给定 n 块红砖,m 块绿砖,问有多少种方式可以建造成最高的塔,每一层颜色必须一样. 析:首先要确定最高是多少层h,大约应该是用 h * (h+1) <= (m+n) * 2,然后dp[i ...

  3. codeforces 399B. Red and Blue Balls 解题报告

    题目链接:http://codeforces.com/problemset/problem/399/B 题目意思:给出 n 个只由 R 和 B 组成的字符串(由上到下排列,相当于栈),问最多可以操作多 ...

  4. 【21.58%】【codeforces 746D】Green and Black Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. Codeforces 746D:Green and Black Tea(乱搞)

    http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...

  6. Codeforces 739C Alyona and towers 线段树

    Alyona and towers 这个题写起来真的要人命... 我们发现一个区间被加上一个d的时候, 内部的结构是不变的, 改变的只是左端点右端点的值, 这样就能区间合并了. 如果用差分的话会简单一 ...

  7. codeforces 478 D. Red-Green Towers(背包)

    题目链接:http://codeforces.com/problemset/problem/478/D 题意:给出红色方块r个,绿色方块g个,问最高能叠几层等腰三角形,而且每一层的颜色必须相同. 题解 ...

  8. Codeforces 739C - Alyona and towers(线段树)

    Codeforces 题目传送门 & 洛谷题目传送门 可能有人会问我为什么为这道 *2500 的 D1C 写题解,我觉得大概是想要在写题解数量上 dd ycx 吧,因为 ycx 到目前为止写了 ...

  9. 【CodeForces 626C】Block Towers

    题意 给你n,m,如果 n个2的倍数和m个3的倍数,这n+m个数各不相同,那么求最大的数的最小值. 分析 方法1:枚举最大值为i,直到 i/2+i/3-i/6(不重复的2或3的倍数)≥n+m,并且要i ...

随机推荐

  1. 【转】Beagleboard:BeagleBoneBlack

    原文网址:http://elinux.org/Beagleboard:BeagleBoneBlack Did you know that elinux.org has Mailing Lists? P ...

  2. O - 覆盖的面积 - hdu 1255(求面积)

    分析:求一层的面积覆盖是非常简单的事情,不过多层面积覆盖应该怎么搞???也是比较简单的事情,只需要用两个变量记录就好了,一个记录覆盖一次的,一个记录覆盖两次的,就很容易解决了 ************ ...

  3. 介绍一款超实用的演讲必备工具 ZoomIt

    最近在整理以前的文件时,发现躺在某个角落的一个超好的实用的小工具——ZoomIt.此工具是 SysinternalsSuite(已被MS收购)众多实用工具的一个. 相信大家在演讲时,经常需要调整屏幕文 ...

  4. solr安装

    Windows solr(tomcat) 1.1. 安装步骤 1.1.1准备工作 1. 服务器:apache-tomcat-7.0.40压缩版,http://localhost:8080/安装是否成功 ...

  5. appium新版本不支持findElementByName,切换到findElementByAndroidUIAutomator

    appium 1.7.6 不支持findElementByName(locator)  不知道为什么? 脚本中许多这样的语句,麻烦事情多了 org.openqa.selenium.InvalidSel ...

  6. zeptoJS:如何像jQuery一样,让滚动变得优雅?

    利用jQuery的animate() 方法,我们很容易实现滚动条的平滑滚动效果: $(function() { $('#top').click( function (e) { $('html, bod ...

  7. 单源最短路径(dijkstra算法)php实现

    做一个医学项目,当中在病例评分时会用到单源最短路径的算法.单源最短路径的dijkstra算法的思路例如以下: 如果存在一条从i到j的最短路径(Vi.....Vk,Vj),Vk是Vj前面的一顶点.那么( ...

  8. cocos2dx 利用CCOrbitCamera实现扑克牌翻牌效果

    [cpp] view plaincopy #include "HelloWorldScene.h" #include "SimpleAudioEngine.h" ...

  9. C# 杨辉三角形算法

    代码如下: static void Main(string[] args) { int[][] Array_int = new int[10][]; //向数组中记录杨辉三角形的值 for (int ...

  10. Linux修改SSH连接数 重启SSH服务

    系统 linux,增加SSH终端连接数最大为1000个 解决方案: vi /etc/ssh/sshd_config 输入/MaxStartups 定位到如下并修改 1)        #MaxStar ...