D - Pyramid of Glasses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others)
Submit Status
Problem 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
Each case 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
3 5 4 8
Sample Output
4 6
Hint
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.
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int N=1e5+10; 5 const int INF=0x3f3f3f3f; 6 const double eps=1-1e-5; 7 int cas=1,T; 8 double dp[110][110]; 9 int main() 10 { 11 //freopen("1.in","w",stdout); 12 // freopen("1.in","r",stdin); 13 // freopen("1.out","w",stdout); 14 //scanf("%d",&T); 15 int n,t; 16 while(scanf("%d%d",&n,&t)==2) 17 { 18 memset(dp,0,sizeof(dp)); 19 int ans=0; 20 memset(dp,0,sizeof(dp)); 21 dp[1][1]=t; 22 if(t) 23 { 24 ans=1; 25 dp[1][1]-=1; 26 for(int i=1;i<n;i++) 27 { 28 double x=0.5; 29 for(int j=1;j<=i;j++) 30 { 31 dp[i+1][j]+=x*dp[i][j]; 32 dp[i+1][j+1]+=x*dp[i][j]; 33 } 34 for(int j=1;j<=i+1;j++) 35 { 36 if(dp[i+1][j]>eps) dp[i+1][j]-=1,ans++; 37 else dp[i+1][j]=0; 38 } 39 } 40 } 41 printf("%d\n",ans); 42 } 43 //printf("time=%.3lf\n",(double)clock()/CLOCKS_PER_SEC); 44 return 0; 45 }
solve.cpp
题解:
直接把全部倒到最上面的杯子,然后模拟往下流,每个杯子满了之后就平均地把溢出的往两边流