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 ;
}

最新文章

  1. ReSharper 8.XXX 注册机
  2. 读取iis日志到sql server
  3. 百度全新的ARM架构服务器,一个2U机箱装6台,每台4个3T硬盘,每个机箱共72TB
  4. WinAPI——钩子函数大全2
  5. 《how to design programs》15章 相互引用的数据定义
  6. Slice到C++映射
  7. Single Number leetcode
  8. 修改linux系统时间和同步
  9. java_IO流读取本地文件
  10. 【一天一道LeetCode】#106. Construct Binary Tree from Inorder and Postorder Traversall
  11. asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程
  12. JAVA取数两个数组交集,考虑重复和不重复元素
  13. formbuild拖拽表单设计器
  14. vue传参二
  15. FMDB使用简介
  16. Nginx 做代理服务器时浏览器加载大文件失败 ERR_CONTENT_LENGTH_MISMATCH 的解决方案
  17. IBM应该请我去做Domino产品设计架构师
  18. 使用MSYS、Notepad++搭建C/C++开发环境
  19. MVC杂碎笔记
  20. JS 得细心的坑位

热门文章

  1. Hibernate 批处理(batch inserts, updates and deletes)
  2. linux上配置spark集群
  3. Kibana 可视化监控报警插件 KAAE 的介绍与使用
  4. POJ 1753 Flip Game【枚举】
  5. Prime Ring Problem---hdu1016(dfs)
  6. MySQL查询count(*)、count(1)、count(field)的区别收集
  7. 学习swift从青铜到王者之swift闭包06
  8. iOS国际化:NSLocalizedString的使用
  9. [原创+分享]Mandelbrot Explorer
  10. MongoDB使用入门