首页 > 其他 > 详细

Codeforces Round #273 (Div. 2) D. Red-Green Towers DP

时间:2017-08-11 13:09:42      阅读:190      评论:0      收藏:0      [点我收藏+]

链接:

http://codeforces.com/problemset/problem/478/D

题意:

给出r个红砖,g个绿砖,问有多少种方法搭成最高的塔。

题解:

举红色球的层数,当第i层为红色是,i层上面有[0,r]个 红色的,可推出dp[i+j]=dp[i+j]+dp[j],最后

再统计红色的个数就行了,红色最少为max(h*(h+1)/2-g,0)。

代码:

31 int dp[MAXN];
32 
33 int main() {
34     ios::sync_with_stdio(false), cin.tie(0);
35     int r, g;
36     cin >> r >> g;
37     int s = r + g;
38     int h = sqrt(s * 2);
39     while (h*(h + 1) / 2 > s) h--;
40     dp[0] = 1;
41     rep(i, 1, h + 1) per(j, 0, r + 1)
42         dp[i + j] = (dp[i + j] + dp[j]) % MOD;
43     int ans = 0;
44     rep(i, max(h*(h + 1) / 2 - g, 0), r + 1) ans = (ans + dp[i]) % MOD;
45     cout << ans << endl;
46     return 0;
47 }

 

Codeforces Round #273 (Div. 2) D. Red-Green Towers DP

原文:http://www.cnblogs.com/baocong/p/7345278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!