[Codeforces676B]Pyramid of Glasses(递推,DP)

题目链接:http://codeforces.com/problemset/problem/676/B

递推,dp(i, j)表示第i层第j个杯子,从第一层开始向下倒,和数塔一样的题。每个杯子1个时间能倒满,从上开始向下倒时间为t,那每个杯子不满的时候对下面的贡献一定是0,所以当dp[i][j]>=1的时候,计数倒满的杯子并且将溢出的酒向下平分。

 1 /*
 2 ━━━━━┒ギリギリ♂ eye!
 3 ┓┏┓┏┓┃キリキリ♂ mind!
 4 ┛┗┛┗┛┃\○/
 5 ┓┏┓┏┓┃ /
 6 ┛┗┛┗┛┃ノ)
 7 ┓┏┓┏┓┃
 8 ┛┗┛┗┛┃
 9 ┓┏┓┏┓┃
10 ┛┗┛┗┛┃
11 ┓┏┓┏┓┃
12 ┛┗┛┗┛┃
13 ┓┏┓┏┓┃
14 ┃┃┃┃┃┃
15 ┻┻┻┻┻┻
16 */
17 #include <algorithm>
18 #include <iostream>
19 #include <iomanip>
20 #include <cstring>
21 #include <climits>
22 #include <complex>
23 #include <fstream>
24 #include <cassert>
25 #include <cstdio>
26 #include <bitset>
27 #include <vector>
28 #include <deque>
29 #include <queue>
30 #include <stack>
31 #include <ctime>
32 #include <set>
33 #include <map>
34 #include <cmath>
35 using namespace std;
36 #define fr first
37 #define sc second
38 #define cl clear
39 #define BUG puts("here!!!")
40 #define W(a) while(a--)
41 #define pb(a) push_back(a)
42 #define Rint(a) scanf("%d", &a)
43 #define Rll(a) scanf("%I64d", &a)
44 #define Rs(a) scanf("%s", a)
45 #define Cin(a) cin >> a
46 #define FRead() freopen("in", "r", stdin)
47 #define FWrite() freopen("out", "w", stdout)
48 #define Rep(i, len) for(int i = 0; i < (len); i++)
49 #define For(i, a, len) for(int i = (a); i < (len); i++)
50 #define Cls(a) memset((a), 0, sizeof(a))
51 #define Clr(a, x) memset((a), (x), sizeof(a))
52 #define Fuint(a) memset((a), 0x7f7f, sizeof(a))
53 #define lrt rt << 1
54 #define rrt rt << 1 | 1
55 #define pi 3.14159265359
56 #define RT return
57 #define lowbit(x) x & (-x)
58 #define onenum(x) __builtin_popcount(x)
59 typedef long long LL;
60 typedef long double LD;
61 typedef unsigned long long Uint;
62 typedef pair<int, int> pii;
63 typedef pair<string, int> psi;
64 typedef map<string, int> msi;
65 typedef vector<int> vi;
66 typedef vector<int> vl;
67 typedef vector<vl> vvl;
68 typedef vector<bool> vb;
69 
70 const int maxn = 11;
71 int n, t;
72 double dp[maxn][maxn];
73 
74 
75 int main() {
76     // FRead();
77     Rint(n); Rint(t);
78     int ret = 0;
79     dp[1][1] = t;
80     For(i, 1, n+1) {
81         For(j, 1, i+1) {
82             if(dp[i][j] >= 1) {
83                 dp[i][j] -= 1;
84                 dp[i+1][j] += (dp[i][j]) / 2;
85                 dp[i+1][j+1] += (dp[i][j]) / 2;
86                 ret++;
87             }
88         }
89     }
90     printf("%d
", ret);
91     RT 0;
92 }
原文地址:https://www.cnblogs.com/kirai/p/5546245.html