列表

详情


NC222864. Byfibonacci

描述

Fibonacci Sequence:
Fibonacci representation : Any natural number  can be expressed as the sum of a set of different Fibonacci numbers.

In particular: f_0 and f_1 are two different Fibonacci numbers.

For example: indicates that  corresponds to at least two Fibonacci representations.

The value of the Fibonacci representation : defined as the product of the Fibonacci numbers in the representation .

For example: . In this representation, the value  is: .

With the above definitions, now, find the sum of all Fibonacci representations’ value of a given number .

To simplify the question, please output the answer modulo lovely .

输入描述

The first line contains a positive integer .

The next T line, each line has a natural number .

输出描述

The output should contain  lines, each line with an integer, which represents the value of the answer modulo lovely .

示例1

输入:

1
7

输出:

21

说明:

(Hint: 7=5+2=5+1+1=3+2+1+1, then 5*2+5*1*1+3*2*1*1=21)

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 356ms, 内存消耗: 49200K, 提交时间: 2022-08-13 16:44:49

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int f[50];
int dp[10000005];
int main(){
	f[0]=1;f[1]=1;
	for (int i=2;i<=34;++i){
		f[i]=f[i-1]+f[i-2];
	}
	dp[0]=1;
	dp[1]=1;
	for (int i=1;i<=34;++i){
		for (int j=min(10000005,3*f[i]);j>=f[i];j--){
			dp[j]=(dp[j]+(1ll*dp[j-f[i]]*f[i])%mod)%mod;
		} 
	} 
	int t;
	scanf("%d",&t);
	while(t--){
		int x;
		scanf("%d",&x);
		printf("%d\n",dp[x]);
	}
} 

上一题