文章目录
- 【蓝桥杯专题】 递归 &递推 (C++ | 洛谷 | acwing)
- 复习
- P5534 【XR-3】等差数列
- P4994 终于结束的起点
- P1028 [NOIP2001 普及组] 数的计算
- 波动数列
- [递归]母牛的故事
- 蓝桥杯:耐摔指数
菜狗现在才开始备战蓝桥杯QAQ
【蓝桥杯专题】 递归 &递推 (C++ | 洛谷 | acwing)
复习
【蓝桥杯真题】 (一) 递归与递推 (Acwing 蓝桥杯 笔记)——链接
P5534 【XR-3】等差数列
-
等差数列公式
-
公式一:Sn = (a1 + an) × n / 2;
-
公式二:Sn = n × a1 + n × (n - 1) × d / 2;
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define per(i, a, n) for(int i = n; i <= a; i --)
#define pb push_back;
#define fs first;
#define sz second;
#include <stdlib.h> // atoi
#define debug cout<<"debug"<<"\n"
#define endl "\n";
const int INF = 0x3f3f3f3f;
const int mod=1e9+7;
const int N = 1e6 + 10;
int a[N];
void solve () {
ll n, d, ans = 0;
cin >> a[0] >> a[1] >> n;
d = a[1] - a[0];
ans = n * a[0] + n * (n - 1) * d / 2;
cout << ans << endl;
}
int main(void){
freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
// cin >> T;
while(T --) solve();
return 0;
}
P4994 终于结束的起点
lj
+
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define per(i, a, n) for(int i = n; i <= a; i --)
#define pb push_back;
#define fs first;
#define sz second;
#include <stdlib.h> // atoi
#define debug cout<<"debug"<<"\n"
#define endl "\n";
const int INF = 0x3f3f3f3f;
const int mod=1e9+7;
const int N = 1e6 + 10;
ll M;
ll fp[10000002];
// int a[N];
ll f(ll i) {
if(fp[i]) return fp[i];
if(i == 1 || i == 2) return fp[i] = 1 % M;
else return fp[i] = (f(i - 1) + f(i - 2)) % M;
}
void solve () {
cin >> M;
ll z = 1;
// rep(i, 2, 1000) {
while(f(z) !=0 || f(z + 1) != 1) {
z ++;
}
cout << z << endl;
}
int main(void){
freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
// cin >> T;
while(T --) solve();
return 0;
}
P1028 [NOIP2001 普及组] 数的计算
链接 链接
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define per(i, a, n) for(int i = n; i <= a; i --)
#define pb push_back;
#define fs first;
#define sz second;
#include <stdlib.h> // atoi
#define debug cout<<"debug"<<"\n"
#define endl "\n";
const int INF = 0x3f3f3f3f;
const int mod=1e9+7;
const int N = 1e6 + 10;
int dp[1001];
int f(int n) {
if(n == 1)return 1;
else if(n == 2) return 2;
if(n % 2 == 0) return f(n - 1) + f(n / 2);
else if(n % 2 == 1) return f(n - 1);
}
void solve () {
int n;
cin >> n;
// cout << f(n) << endl; //TLE
rep(i, 1, n) {
rep(j, 1, i / 2) {
dp[i] += dp[j];
}
dp[i] ++;
}
cout << dp[n] << endl;
}
int main(void){
freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
// cin >> T;
while(T --) solve();
return 0;
}
波动数列
链接 链接
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define per(i, a, n) for(int i = n; i <= a; i --)
#define pb push_back;
#define fs first;
#define sz second;
#include <stdlib.h> // atoi
#define debug cout<<"debug"<<"\n"
#define endl "\n";
const int INF = 0x3f3f3f3f;
const int mod=100000007;
const int N = 1005;
int n , s, a, b;
int f[N][N];
// 那
int get_mod (int a, int b) {
return (a % b + b) % b;
}
void solve () {
cin >> n >> s >> a >> b;
f[0][0] = 1;
for(int i = 1 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
f[i][j] = (f[i - 1][get_mod(j - i * a , n)] + f[i - 1][get_mod(j + i * b, n)]) % mod;
cout << f[n - 1][get_mod(s, n)] << endl;
}
int main(void){
freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
// cin >> T;
while(T --) solve();
return 0;
}
[递归]母牛的故事
链接 链接
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;
typedef long long ll;
typedef double db;
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define per(i, a, n) for(int i = n; i <= a; i --)
#define pb push_back;
#define fs first;
#define sz second;
#include <stdlib.h> // atoi
#define debug cout<<"debug"<<"\n"
#define endl "\n";
const int INF = 0x3f3f3f3f;
const int mod=1e9+7;
const int N = 1e5 + 10;
int f[56] = {0, 1, 2, 3, 4};
// ! 递归可能超时 建议 记忆化搜索
// 递归题 写前几项规律 或许可以碰运气
int dfs(int n) {
if(n <= 4) return n;
else if (f[n] == 0) {
f[n] = dfs(n - 1) + dfs(n - 3); ///数组记录递归结果,加快速度,记忆递归
return f[n];
}
else if (f[n] != 0) {
return f[n];
}
}
void solve () {
int n;
// cin >> n
while(cin >> n) {
// cin >> n;
if(n == 0) break;
// cout << n << endl;
cout << dfs(n) << endl;
}
}
int main(void){
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
// cin >> T;
while(T --) solve();
return 0;
}
蓝桥杯:耐摔指数
补题 递推
https://www.lanqiao.cn/problems/?first_category_id=1&page=7&sort=pass_rate&second_category_id=3&tags=%E9%80%92%E6%8E%A8
链接 链接