NC222864. Byfibonacci
描述
输入描述
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]); } }