Pyramid of Glasses(递推)
1 second
256 megabytes
standard input
standard output
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of n glasses.
Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid.
Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in t seconds.
Pictures below illustrate the pyramid consisting of three levels.


The only line of the input contains two integers n and t (1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle.
Print the single integer — the number of completely full glasses after t seconds.
3 5
4
4 8
6
In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty.
题意:每1s会从上面多出一杯子的水,然后问你t秒后会有多少个杯子是满的,n代表有多少层杯子
题解:找到递推式的话,这题并不难。我们考虑,每个杯子(除了最上面那个),他们获得的水都是从上面两边获得,而上面的杯子的水只会流向两边,那么递推式就很明显了。我们假设杯子容量为1,那状态就是dp[i][j]=(dp[i-1][j-1]-1)/2+(dp[i-1][j]-1)/2;初始条件dp[1][1]=t*1;一路推下来,记录dp[i][j]>=1的个数,即为答案。
#include <cstdio>
using namespace std;
double dp[][];
int main()
{
int n,t,ans=;
scanf("%d%d",&n,&t);
dp[][]=t;
for (int i=;i<=n;i++)
for (int j=;j<=i;j++)
{
if (dp[i-][j-]>)
dp[i][j]+=(dp[i-][j-]-)/;
if (dp[i-][j]>)
dp[i][j]+=(dp[i-][j]-)/;
if (dp[i][j]>=) ans++;
}
printf("%d\n",t==?:ans);
}
Pyramid of Glasses(递推)的更多相关文章
- 2018南京区域赛G题 Pyramid——找规律&&递推
先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-5}$,根据特征根理论可求出特征方程 $ ...
- [Codeforces676B]Pyramid of Glasses(递推,DP)
题目链接:http://codeforces.com/problemset/problem/676/B 递推,dp(i, j)表示第i层第j个杯子,从第一层开始向下倒,和数塔一样的题.每个杯子1个时间 ...
- 【BZOJ-2476】战场的数目 矩阵乘法 + 递推
2476: 战场的数目 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 58 Solved: 38[Submit][Status][Discuss] D ...
- 从一道NOI练习题说递推和递归
一.递推: 所谓递推,简单理解就是推导数列的通项公式.先举一个简单的例子(另一个NOI练习题,但不是这次要解的问题): 楼梯有n(100 > n > 0)阶台阶,上楼时可以一步上1阶,也可 ...
- Flags-Ural1225简单递推
Time limit: 1.0 second Memory limit: 64 MB On the Day of the Flag of Russia a shop-owner decided to ...
- 利用Cayley-Hamilton theorem 优化矩阵线性递推
平时有关线性递推的题,很多都可以利用矩阵乘法来解决. 时间复杂度一般是O(K3logn)因此对矩阵的规模限制比较大. 下面介绍一种利用利用Cayley-Hamilton theorem加速矩阵乘法的方 ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- 简单递推 HDU-2108
要成为一个ACMer,就是要不断学习,不断刷题...最近写了一些递推,发现递推规律还是挺明显的,最简单的斐波那契函数(爬楼梯问题),这个大家应该都会,看一点稍微进阶了一点的,不是简单的v[i] = v ...
- [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...
随机推荐
- bootstrap页面模板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)
#include<cstdio>#include<cstdlib>#include<cstring>int main(){ char s[80];//输入OOXXO ...
- Shell学习笔记 ——第二天
1.显示日期 date | cal cal 2010 cal 2 2010 2.改变文件拥有者 chown 3.改变文件权限 chmod 4.显示当前目录 pwd 5.查看文件尾部内容,并 ...
- HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法
禁止鼠标右键.禁止全选.复制.粘贴: oncontextmenu事件禁用右键菜单: js代码: document.oncontextmenu = function(){ event.returnVal ...
- Pthon修炼5
函数 一.自定义函数 def:表示函数的关键字 函数名:函数的名称 函数体:函数中进行一系列的逻辑计算 参数:为函数体提供数据 返回值:执行完函数return 一个值 例:def count(x ...
- android studio的lib和jniLibs
在android studio 中添加jar和so时,将jar文件直接拷贝到 项目目录\app\libs下即可,将so文件按照平台分类目录放到 项目目录\app\src\main\jniLibs\平台 ...
- C#使用SqlDataAdapter 实现数据的批量插入和更新
近日由于项目要求在需要实现中型数据的批量插入和更新,晚上无聊,在网上看到看到这样的一个实现方法,特摘抄过来,以便以后可能用到参考. 一.数据的插入 DateTime begin = DateTime. ...
- 获取所有input值 处理成json格式再利用$.post提交
<script>$(document).ready(function(){ $("#sub").click(function(){ var ...
- IDEA Mybatis 找不到映射器xml文件
用IDEA新建了一个测试MyBatis工程,工程目录如下 其中config是MyBatis的配置文件,内容如下 <?xml version="1.0" encoding=&q ...
- SQL 范式(转载)
装载于"http://www.cnblogs.com/KissKnife/ 理论性的东西,往往容易把人人都看得懂的东西写成连鬼都看不懂,近似于主任医生开的药方.从前学范式的时候,把书中得概念 ...