The original question, please poke here
Test instructions
Put the cup into a Yang Hui triangle, that is, the top 1 cups, the second Layer 2 cups, ... Nth Layer N Cups.
Every second can fill 1 cups, each time a cup is full, the cocktail party is divided into the bottom of it to support its two cups.
As shown in. 1 ≤ n ≤ 10, 0≤ t ≤10 000.
Analysis: Because n is small, it is a recursive process to directly simulate this process.
Note that if recursion is not recursive to the n+1 layer, then the last statistic is the number of statistics >=1 rather than the number of ==1,
Because when the wine can fill the cup larger than the N-Layer Cup (n+1)/2<t, the recursive process terminates on the N-level and cannot be pushed down. So the bottom
A layer of wine is greater than 1. The code is as follows:
#include <cstdio>#include<map>#include<algorithm>#include<iostream>#include<Set>#include<cmath>#include<cstring>using namespaceStd;typedefLong Longll;Doublep[ A][ A];intMain () {intn,t; while(~SCANF ("%d%d",&n,&t) {memset (P,0,sizeof(p)); for(intI=1; i<=t;i++) {p[1][1]+=1; for(intj=1; j<n;j++) { for(intk=1; k<=j;k++) { //cout<<j<< ' <<k<<endl; if(p[j][k]>1) {p[j+1][k] + = (p[j][k]-1)/2; P[j+1][k+1] + = (p[j][k]-1)/2; P[J][K]=1; //cout<<i<<endl; //cout<<j+1<< ' <<k<< ' <<p[j+1][k]<<endl; //cout<<j+1<< ' <<k+1<< ' <<p[j+1][k+1]<<endl; } } } } intCNT =0; for(intj=1; j<=n;j++) { for(intk=1; k<=j;k++) { if(p[j][k]>=1) CNT++; }} cout<<cnt<<Endl; } return 0;}
View Code
If you push to the n+1 layer, the number of ==1 is counted.
#include <cstdio>#include<map>#include<algorithm>#include<iostream>#include<Set>#include<cmath>#include<cstring>using namespaceStd;typedefLong Longll;Doublep[ A][ A];intMain () {intn,t; while(~SCANF ("%d%d",&n,&t) {memset (P,0,sizeof(p)); for(intI=1; i<=t;i++) {p[1][1]+=1; for(intj=1; j<=n;j++)//<=n guaranteed recursion to n+1 layer { for(intk=1; k<=j;k++) { if(p[j][k]>1) {p[j+1][k] + = (p[j][k]-1)/2; P[j+1][k+1] + = (p[j][k]-1)/2; P[J][K]=1; } } } } intCNT =0; for(intj=1; j<=n;j++) { for(intk=1; k<=j;k++) { if(p[j][k]==1)//cnt++; }} cout<<cnt<<Endl; } return 0;}
Codeforces Round #354 (Div. 2) B. Pyramid of Glasses (analog + thinking)