*/intmain(){// freopen("D://rush.txt","r",stdin);ios::sync_with_stdio(false);intr,g; cin>>r>>g;inth=1;while(h*(h+1)/2<=r+g) h++; h--;intsum=h*(h+1)/2;// cout<<h<<endl;dp[0]=1;for(inti=1;i<=h;i++) {for(intj=r;j>=i;j--)//逆序的滚动数组{ dp...
codeforces 478 D. Red-Green Towers(背包) 题目链接:http://codeforces.com/problemset/problem/478/D 题意:给出红色方块r个,绿色方块g个,问最高能叠几层等腰三角形,而且每一层的颜色必须相同。 题解:一道简单的背包问题,设dp[i]表示放了i个红方块一共有几种方案。 1 2 3 4 5 6 7 8 9 10 11 12...
然后遍历状态的时候用一个 \(vis\) 数组判断一下是不是最后一层(如果这一层扩展不出来任何新的状态,那么这一层的上一层就是最后一层)。 示例代码: #include <bits/stdc++.h> using namespace std; const int maxn = 200020; const long long MOD = 1000000007LL; int r, g; long long f[2][maxn...
4. Codeforces 872C Maximum splitting:数学【分解成合数之和】(829) 5. Codeforces 897C Nephren gives a riddle:模拟【珂学】(792) 评论排行榜 1. Codeforces 909C Python Indentation:树状数组优化dp(2) 2. Codeforces 478D Red-Green Towers:dp(1) 最新评论 1. Re:Codeforces 478D Red-Green T...
Codeforces478D-Red-Green Towers-DP 不是特别难的一道dp题。 给r个红块,g个绿块,计算这些块能磊出的最高塔的方案数。 塔的每一层都比上一层多一块,每一层只能有一种颜色。 dp[i][j]表示第i层,j个红块的方案数。 则dp[i][j] = dp[i-1][j] + dp[i-1][j-i].注意一下方案的转移和...
Codeforces 478D Red-Green Towers http://codeforces.com/problemset/problem/478/D思路:dp:f[i][j]代表当前第i层,用了j个绿色方块的方案数,用滚动数组,还有,数组清零的时候一定要用memset,不然for的常数太大。。1 #include<cstdio> 2 #include<cmath> 3...
Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks. Two red-green towers ...
CF478D Red-Green Towers 题解 动态规划 题目链接:https://codeforces.com/problemset/problem/478/D 解题思路: 定义f[i][j]f[i][j] 表示第 ii 层并且总使用了 jj 个红色格子的方案总数。 则:f[i][j]=f[i−1][j]+f[i−1][j−h]f[i][j]=f[i−1][j]+f[i−1][j−h](...
D. Red-Green Towers Dp 题意:有两种颜色的积木 向上垒,每层只能是同一种颜色,且每层的个数等于层数。问有多少种垒法。 Dp滚动数组搞下就好了。 #include <cstdio>#include<cstring>#include<algorithm>#include<climits>#include<string>#include<iostream>#include#include<cstdlib>#include<list>#include...
D. Red-Green Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: Red-green tower is consisting of...