这跟前面做的蓝桥杯省赛-积木画一个类型,但是递推更简单些
凭什么,同样是第五题,这跟Java那边都不是一个难度的
#include<iostream>
#include<vector>
using namespace std;
const int mod = 99999;
vector<int> res;
void handle(int len) {
vector<int> dp(len+1);
dp[0] = 1;
dp[1] = 5;
// dp[2] = 33;
// dp[2] = 5*dp[1] + 2*4*dp[i-2];
// dp[3] = dp[2]*5+8*dp[i-2] = 205
// dp[4] = 5*dp[3] + 8*dp[2]
for (int i = 2; i <= len; i++)
dp[i] = (5 * dp[i - 1] % mod + 8 * dp[i - 2] % mod) % mod;
res.push_back(dp[len]);
}
int main() {
int n;
cin >> n;
int in;
for (int i = 0; i < n; i++) {
cin >> in;
handle(in);
}
for (int i : res) cout << i << " " << endl;
return 0;
}
标签:handle,int,res,国赛,计挑,C++,include,dp
From: https://www.cnblogs.com/yaocy/p/17017517.html