[BZOJ 2796]POI2012 Fibonacci Representation
来源:互联网 发布:centos 7和ubuntu 编辑:程序博客网 时间:2024/05/17 01:21
大概就是说假设 F(x)<=a<=F(x+1),答案d[n]=min( d[a-F(x)] , d[F(x+1)-a] )+1
记忆化一下就行了。
证明吗。。。这个坑再填吧。。。
#include <map> #include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;LL f[110],n;int Q,i;map <LL,int> hash;int dfs(LL x){ if (hash[x]!=0) return hash[x]; int t=lower_bound(f+1,f+90,x)-f; if (f[t]==x) return 1; hash[x]=min(dfs(x-f[t-1]),dfs(f[t]-x))+1; return hash[x];}int main(){ freopen("roz.in","r",stdin); freopen("roz.out","w",stdout); f[0] = f[1] = 1; for (i=2;i<=90;i++) f[i]=f[i-1]+f[i-2]; scanf("%d",&Q); while (Q--){ scanf("%I64d\n",&n); hash.clear(); printf("%d\n", dfs(n) ); } return 0;}
0 0
- [BZOJ 2796]POI2012 Fibonacci Representation
- BZOJ 2796: [Poi2012]Fibonacci Representation
- 2796: [Poi2012]Fibonacci Representation
- bzoj 2796: [Poi2012]Fibonacci Representation 记忆化搜索
- 【POI2012】【BZOJ2796】Fibonacci Representation
- BZOJ2796: [Poi2012]Fibonacci Representation
- BZOJ2796 [Poi2012]Fibonacci Representation
- BZOJ2796/POI2012 Fibonacci Representation
- BZOJ2796: [Poi2012]Fibonacci Representation
- 【bzoj2796】 [Poi2012]Fibonacci Representation
- bzoj2796 [Poi2012]Fibonacci Representation
- bzoj2796 [Poi2012]Fibonacci Representation 贪心
- 2796: [Poi2012]Fibonacci Representation 思路题 map+记忆化搜索
- BZOJ 2789: [Poi2012]Letters
- [BZOJ 2790]POI2012 Distance
- [BZOJ 2789]POI2012 Letters
- [BZOJ 2791]POI2012 Rendezvous
- [BZOJ 2803]Poi2012 Prefixuffix
- 文件读写权限更改
- Error: ShouldNotReachHere()
- 由一篇写模拟电路设计的好文章所想到的
- tppabs这个属性是什么?
- Pallet-欧标托盘
- [BZOJ 2796]POI2012 Fibonacci Representation
- JQuery树形显示笔记
- Java并发——函数yield(),sleep()和wait()的区别
- cocos2d-x基础学习--添加触摸事件
- .lds的作用
- android sharedpreferences 保存 list<Map<String,Object>>数据
- C++中的类所占内存空间总结
- wikioi 2665 三角形判断
- Android--sharepreference总结