bzoj2660
2024-08-30 00:40:05
dp
看了挺长时间的,这篇写的很好:http://97littleleaf11.xyz/oi/bzoj-2660/
我们先把n按照斐波那契数列贪心分解,然后发现可以把现在组合的斐波那契数分解成两个较小的,具体看博客,然后就是dp转移,上面的博客图画的很清楚了,转移就很方便
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = ;
int top;
long long n;
long long f[N], dp[N][], st[N];
int main()
{
cin >> n;
f[] = ;
f[] = ;
for(int i = ; i <= ; ++i) f[i] = f[i - ] + f[i - ];
for(int i = ; i; --i) if(n - f[i] >= )
{
n -= f[i];
st[++top] = i;
}
reverse(st + , st + top + );
dp[][] = ;
dp[][] = (st[] - ) >> ;
for(int i = ; i <= top; ++i)
{
dp[i][] = dp[i - ][] + dp[i - ][];
dp[i][] = dp[i - ][] * ((st[i] - st[i - ]) >> ) + dp[i - ][] * ((st[i] - st[i - ] - ) >> );
}
cout << dp[top][] + dp[top][];
return ;
}
最新文章
- ReSharper 8.XXX 注册机
- 读取iis日志到sql server
- 百度全新的ARM架构服务器,一个2U机箱装6台,每台4个3T硬盘,每个机箱共72TB
- WinAPI——钩子函数大全2
- 《how to design programs》15章 相互引用的数据定义
- Slice到C++映射
- Single Number leetcode
- 修改linux系统时间和同步
- java_IO流读取本地文件
- 【一天一道LeetCode】#106. Construct Binary Tree from Inorder and Postorder Traversall
- asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程
- JAVA取数两个数组交集,考虑重复和不重复元素
- formbuild拖拽表单设计器
- vue传参二
- FMDB使用简介
- Nginx 做代理服务器时浏览器加载大文件失败 ERR_CONTENT_LENGTH_MISMATCH 的解决方案
- IBM应该请我去做Domino产品设计架构师
- 使用MSYS、Notepad++搭建C/C++开发环境
- MVC杂碎笔记
- JS 得细心的坑位
热门文章
- Hibernate 批处理(batch inserts, updates and deletes)
- linux上配置spark集群
- Kibana 可视化监控报警插件 KAAE 的介绍与使用
- POJ 1753 Flip Game【枚举】
- Prime Ring Problem---hdu1016(dfs)
- MySQL查询count(*)、count(1)、count(field)的区别收集
- 学习swift从青铜到王者之swift闭包06
- iOS国际化:NSLocalizedString的使用
- [原创+分享]Mandelbrot Explorer
- MongoDB使用入门