Pyramid of Glasses

来源:互联网 发布:有好看衣服的淘宝店铺 编辑:程序博客网 时间:2024/05/20 06:53

    昨天的最后一题,感觉也没有多大的难度……可就是没有敲出来……见题:


E - 
Pyramid of Glasses
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 676B

Description

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 2 glasses 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.

Input

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.

Output

Print the single integer — the number of completely full glasses after t seconds.

Sample Input

Input
3 5
Output
4
Input
4 8
Output
6
    理解:该题的意思是自顶向下倒酒,每秒倒一杯酒的量,连续倒t秒,求在n层t秒时有多少酒杯是满的。

    该题通过画图可以很容易地看出dp方程,若dp[i-1][j-1]大于0 或者 dp[i-1][j]-1) 大于0  dp[i][j]+=(dp[i-1][j-1]-1)/2;  dp[i][j]+=(dp[i-1][j]-1)/2。可以将倒了t秒的酒当作总的流量,用dp数组表示流经酒杯的总的流量,若流量大于等于1的话,则酒杯肯定能够倒满。这么理解不难写出代码:

//该题  构建dp 方程   若dp[i-1][j-1]大于0 或者 dp[i-1][j]-1) 大于0  dp[i][j]+=(dp[i-1][j-1]-1)/2;  dp[i][j]+=(dp[i-1][j]-1)/2;//n秒 即总共倒了n杯的水  连起来 自顶到底地分散开去#include <cstdio>using namespace std;double dp[15][15];int main(){int n,t,ans=1;scanf("%d%d",&n,&t);dp[1][1]=t;for (int i=2; i<=n; i++)for (int j=1; j<=i; j++){if (dp[i-1][j-1]>1)    //如果上左杯中大于一dp[i][j]+=(dp[i-1][j-1]-1)/2;if (dp[i-1][j]>1)      //如果上面杯中大于一dp[i][j]+=(dp[i-1][j]-1)/2;if (dp[i][j]>=1) ans++; //分流的同时进行计数判断}//打印dp数组理解/*for(int i=1; i<=n; i++){for(int j=1; j<=i; j++)printf("%lf ",dp[i][j]);printf("\n");}*/printf("%d\n",t==0?0:ans);}
    总结:碰到这类题目还是不要去盲目笔算找规律,浪费时间且运算量大很容易影响心态。尽量往算法有关联上去靠,盲目运算得不偿失,失去了计算机运算的优势。还是见识太浅,还是得加油。

    特记下,以备后日回顾。

0 0
原创粉丝点击