简略题意:问 k 个斐波那契数不能组成的最小的数是多少。
DP打个表,发现规律很显然是
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 998244353;
const int maxn = 2;
struct Matrix{
int a[maxn][maxn];
Matrix(){
memset(a, 0, sizeof a);
}
void Init(){
for(int i=0; i<maxn; i++)
for(int j=0; j<maxn; j++)
a[i][j] = (i == j);
}
Matrix operator + (const Matrix & B) const{
Matrix C;
for(int i=0; i<maxn; i++)
for(int j=0; j<maxn; j++)
C.a[i][j] = (a[i][j] + B.a[i][j])%mod;
return C;
}
Matrix operator * (const Matrix & B) const{
Matrix C;
for(int i=0; i<maxn; i++)
for(int j=0; j<maxn; j++)
for(int k=0; k<maxn; k++){
C.a[i][j] = (C.a[i][j] + (1LL*a[i][k] * B.a[k][j])%mod)%mod;
}
return C;
}
Matrix operator ^ (const LL &t)const{
Matrix A = (*this), res;
res.Init();
LL p = t;
while(p){
if(p & 1) res = res * A;
A = A * A;
p >>= 1;
}
return res;
}
} mat;
Matrix trans;
int f(int x) {
if(x == 0) return 0;
if(x == 1) return 1;
Matrix ans;
ans.a[0][0] = 1, ans.a[0][1] = 0;
ans.a[1][0] = 0, ans.a[1][0] = 0;
return ((trans^(x-1))*ans).a[0][0];
}
int main() {
trans.a[0][0] = 1, trans.a[0][1] = 1;
trans.a[1][0] = 1, trans.a[1][1] = 0;
int n;
while(~scanf("%d", &n)) {
printf("%lld\n", ((1LL*f(2*n+3))-1+mod)%mod);
}
return 0;
}
附上暴力程序
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
int f[111];
int dp[11111111];
int main() {
f[0] = 0, f[1] = 1;
for(int i = 2; i <= 30; i++)
f[i] = f[i-1] + f[i-2], cout<<i<<" "<<f[i]<<endl;
dp[0] = 1;
for(int k = 1; k <= 9;k++) {
for(int j = 10000; j >= 0; j--){
for(int k = 0; k < 30; k++) {
dp[j+f[k]] |= dp[j];
}
}
int p = 0;
while(1) {
if(!dp[p]) {
cout<<k<<" "<<p<<endl;
break;
}
p++;
}
}
return 0;
}