当前位置:网站首页>2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
2022-07-30 22:55:00 【_Kiwi_Berry_】
题意:
给一个数x,问有多少个 Fibonacci The subset sum isx
思路:
如果 n 的范围较小,那就是01背包,但 n<=1e7 You cannot use a range as a state,但我们可以发现看题解 :设 v1 , v2 为小于 x 的 Fibonacci 最大值和次大值,Then the eligible subset has one and only one of them.
After you find this rule, you canDP了,我们令
- dp[0][i] 表示 i Pick the sum of the products of the largest Fibonacci numbers
- dp[1][i] 表示 i Pick the sum of the products of the next largest Fibonacci numbers
namo 转移方程则为
- dp[0][i]=(dp[0][i-v1]+dp[1][i-v1])*v1
- dp[1][i]=(dp[0][i-v2]+dp[1][i-v2])*v2; i-v2<v2
- dp[1][i]=(dp[1][i-v2])*v2; i-v2>=v2
Code:
#include <bits/stdc++.h>
// #define debug freopen("_in.txt", "r", stdin);
#define debug freopen("_in.txt", "r", stdin), freopen("_out.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
typedef struct Node *bintree;
using namespace std;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll maxn = 1e7 + 10;
const ll maxm = 2e6 + 10;
const ll mod = 998244353;
const double pi = acos(-1);
const double eps = 1e-8;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
ll T, n, m, q, d, kase = 0;
priority_queue<pair<ll, ll>> que;
ll arr[100];
ll dp[3][maxn];
void solve()
{
scanf("%lld", &n);
printf("%lld\n",(dp[0][n]+dp[1][n])%mod);
}
signed main()
{
// debug;
scanf("%lld", &T);
// T = 1;
arr[1] = arr[2] = 1;
for (ll i = 2; i <= 50; i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
}
dp[0][0] = 1;
dp[0][1] = 1;
dp[1][1] = 1;
ll now = 0;
for (ll i = 2; i <= 1e7; i++)
{
if (i >= arr[now])
{
while (i >= arr[now])
{
now++;
}
now--;
}
ll v1=arr[now],v2=arr[now-1];
dp[0][i]=(dp[0][i-v1]+dp[1][i-v1])*v1;
dp[0][i]%=mod;
if(i-v2<v2)
{
dp[1][i]=(dp[0][i-v2]+dp[1][i-v2])*v2;
}
else
{
dp[1][i]=(dp[1][i-v2])*v2;
}
dp[1][i]%=mod;
}
while (T--)
{
solve();
}
}
边栏推荐
猜你喜欢
MySQL索引常见面试题(2022版)
IJCAI2022教程 | 口语语言理解:最新进展和新领域
MYSQL JDBC Book Management System
[MySQL] Related operations on databases and tables in MySQL
【无标题】
When Navicat connects to MySQL, it pops up: 1045: Access denied for user 'root'@'localhost'
宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元
Py's pdpbox: a detailed introduction to pdpbox, installation, and case application
Go1.18升级功能 - 泛型 从零开始Go语言
【Untitled】
随机推荐
Difference between cookie and session
Go的Gin框架学习
d违反常了吗
cnpm安装步骤
BFS题单总结
ClickHouse to create a database to create a table view dictionary SQL
Detailed operator
Successfully solved ImportError: always import the name '_validate_lengths'
@RequestBody、 @RequestParam 、 @PathVariable 和 @Vaild 注解
【微信小程序】小程序突破小程序二维码数量限制
Jetson AGX Orin 平台关于c240000 I2C总线和GMSL ses地址冲突问题
go版本升级
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
史上最全的Redis基础+进阶项目实战总结笔记
d使用among的问题
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
【无标题】
Abstract classes and interfaces (study notes)
cnpm的安装与使用
VS2017编译Tars测试工程