bzoj 2796: [Poi2012]Fibonacci Representation
2024-10-08 15:38:18
结论貌似是,,,肯定只有没有重复的数字。http://hzwer.com/6426.html
一开始猜的是贪心,感觉也是可以的啊。。。(想想都有道理,然而看到是神奇的(dp类)记忆化搜索,直接虚的不敢写。。)
#include <bits/stdc++.h>
#define LL long long
#define lowbit(x) x&(-x)
#define inf 2e18
using namespace std;
inline LL ra()
{
LL x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
LL f[],n;
int top,P;
map<LL, int > F;
int solve(LL x)
{
if (F[x]) return F[x];
int t=lower_bound(f,f+top,x)-f;
if (f[t]==x) return ;
return F[x]=min(solve(x-f[t-]),solve(f[t]-x))+;
}
int main()
{
f[]=; f[]=;
for (int i=; f[i-]<=inf; i++,top++) f[i]=f[i-]+f[i-];
P=ra();
for (int i=; i<=P; i++)
printf("%d\n",solve(ra()));
return ;
}
最新文章
- [Penetration Testing Devil Training Camp Based on Metasploit] Learn &; Practice
- linux 多线程基础
- Jenkins console输出乱码???
- 前端工程师IE6兼容性问题随笔(未完待续)
- JavaScript的Ajax请求示例
- 10、技术经理要阅读的书籍 - IT软件人员书籍系列文章
- Jstat在分析java的内存GC时的应用
- mysql 前缀索引
- C语言 电梯函数
- CSS3新的字体尺寸单位rem
- tomcat上servlet程序的配置与处理servlet请求过程
- JDK中日期和时间的几个常用类浅析(三)
- 访问Access日期字段
- vue 2.0 scopedSlots和slots在render函数中的应用示例
- python itertools 模块
- Python之旅Day7 面向对象&;异常处理
- Python Tkinter 简单使用
- elk-nginx输出json格式的日志
- jmeter函数简介
- 树莓派 SD卡镜像备份