递推+高精度(所以python)
k=int(input())
a = 0
b = 0
for i in range(1, k + 1):
b = a + pow(2, i)
a = b
print(b)
递推 斐波那契数列
#include<bits/stdc++.h>
using namespace std;
long long res[120];
int main() {
int t;
cin >> t;
res[1] = 1, res[2] = 2;
for(int i = 3; i <= 100; i++)
res[i] = res[i - 1] + res[i - 2];
while(t--) {
int n;
cin >> n;
cout << res[n] << endl;
}
return 0;
}
递推 用res[i]表示iloveyou匹配了前i个的字符的子序列数,当遇到第i个字符,则之前匹配了前i-1个的字符的子序列都可以变为匹配了前i个的字符的子序列,即res[i]=res[i]+res[i-1]
#include <bits/stdc++.h>
using namespace std;
const int MOD = 20010905;
char c, str[8]= {'i','l','o','v','e','y','o','u'};
int res[8];
int main() {
res[0]=1;
while(~scanf("%c",&c)) {
for(int i = 0 ; i < 8; i++) {
if(c == str[i] || c == str[i] - 32)
res[i + 1] = (res[i + 1] + res[i]) % MOD;
}
}
cout << res[8] << endl;
return 0;
}