学习目标:
博主介绍: 27dCnc
专题 : 数据结构帮助小白快速入门算法
👍👍👍👍👍👍👍👍👍👍👍👍
☆*: .。. o(≧▽≦)o .。.:*☆
Github今日打卡
- ACM题解
学习时间:
- 周一至周五晚上 7 点—晚上9点
- 周六上午 9 点-上午 11 点
- 周日下午 3 点-下午 6 点
学习内容:
- 超级楼梯
- 数列求值
内容详细:
超级楼梯
题目考点: 动态规划
思路
步数的叠加,但是注意初始化
详细代码
#include<bits/stdc++.h>
#define Run 1
#define endl "\n"
#define N 1000
using unl = __int128_t;
using ll = long long;
using namespace std;
class Solution {
public:
void slove() {
ll n; cin >> n;
ll a[N];
a[1] = 0;
a[2] = 1; //从2开始
a[3] = 2;
for (ll i = 4; i <= 40;i++) {
a[i] = a[i - 1] + a[i - 2];
}
cout << a[n] << endl;
}
};
signed main() {
cin.tie(0) -> ios::sync_with_stdio(0);
cout.tie(0) -> ios::sync_with_stdio(0);
#if Run
int _;cin>>_;while(_--) Solution().slove();
#else
Solution().slove();
#endif
return 0;
}
数列求值
题目考点: 数列
动态规划
同余定理
思路
只要运用基础的动态规划的思维,将前三个数据,相加可能会超出内存
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e4;
LL dp[20190325]; //数列从1下标开始
int main() {
LL n;
dp[0] = 1;dp[1] = 1;dp[2] = 1;
while (cin >> n) {
for (auto i = 3; i <= n; i ++) {
dp[i] = (dp[i - 1] + dp[i - 2] + dp[i - 3]) % 10000; //同余定理
}
cout << dp[n - 1] << "\n";
}
}
学习产出:
- 技术笔记 2 遍
- CSDN 技术博客 3 篇
- 习的 vlog 视频 1 个
重磅消息:
GTP - 4 最新版接入服务他来了 点击链接即可查看详细
🔥如果此文对你有帮助的话,欢迎💗关注、👍点赞、⭐收藏、✍️评论,支持一下博主~