ABC260C
这个题可以用dp做(暂时不会)可以用递归做,感觉通过这个题知道了边界条件要找到核心点,我找到了以等级为主,但是在最后处理红蓝宝石数量的时候,简单的通过cnt_b统计了蓝宝石的数量,但是实际上核心点是判断是不是红宝石,如果是就可以返回个数,然后在递归的时候直接统计蓝色宝石的数量,把递推和递归想混了。后面的是递推做法,比较简单。
递归做法
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, x , y;
ll dfs(bool is_red, int grade){
if(grade == 1) return is_red? 0 : 1;
if(is_red){
return dfs(true, grade - 1)+dfs(false, grade)*x;
}
else{
return dfs(true, grade - 1)+dfs(false, grade - 1)*y;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x >> y;
cout <<dfs(true, n)<<endl;
return 0;
}
递推做法
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int n, x, y;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x >> y;
vector<ll> r(n), b(n);
r[n] = 1;
for(int i = n; i >= 2; i--){
r[i-1] += r[i];
b[i - 1]+=r[i] * x;
r[i - 1] += b[i];
b[i - 1] += b[i] * y;
}
cout << b[1] << endl;
return 0;
}
```

浙公网安备 33010602011771号