2796: [Poi2012]Fibonacci Representation 思路题 map+记忆化搜索
来源:互联网 发布:may it be mv 编辑:程序博客网 时间:2024/06/05 00:22
POI的题果然神。。不会做啊。。
令
联立得:
所以如果一个数出现了两次,可以把它转化为两个不同的数,所以总存在一个合法的解,使得每个数出现最多一次。
我们用
当
否则
#include<iostream>#include<cstdio>#include<queue>#include<set>#include<map>#include<algorithm>#define inf 2e18#define ll long long using namespace std;map<ll,int> F;ll n,f[1005];int top;inline ll read(){ ll a=0,f=1; char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();} return a*f;}int solve(ll x){ if (F[x]) return F[x]; int b=lower_bound(f,f+top,x)-f; if (f[b]==x) return 1; return F[x]=min(solve(x-f[b-1]),solve(f[b]-x))+1;}int main(){ f[0]=f[1]=1; for (int i=2;f[i-1]<=inf;i++,top++) f[i]=f[i-1]+f[i-2]; int testcase=read(); while (testcase--) { n=read(); printf("%d\n",solve(n)); } return 0;}
0 0
- 2796: [Poi2012]Fibonacci Representation 思路题 map+记忆化搜索
- bzoj 2796: [Poi2012]Fibonacci Representation 记忆化搜索
- 2796: [Poi2012]Fibonacci Representation
- [BZOJ 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 贪心
- [POI 2012]Fibonacci Representation(记忆化DFS)
- hdoj5167Fibonacci【map记录记忆化搜索】
- 2792: [Poi2012]Well 思路题 二分答案
- zoj 3644 记忆化搜索与map映射
- 动态规划优化之使用Map记忆化搜索
- zoj3777 Problem Arrangement(状压dp,思路赞)
- Masonry介绍与使用实践:快速上手Autolayout
- Linux操作系统的主要组成部分
- 请把Camera hold住 - Android高通平台调试Camera驱动全纪录
- shiro 注解没起作用
- 2796: [Poi2012]Fibonacci Representation 思路题 map+记忆化搜索
- 史上最全的iOS面试题及答案
- 借助Excel公式自动导出VC资源中的所需控件ID列表
- CAS单点登录原理分析
- 华为经典面试题---大数乘法的c++实现
- 怎样实现ABBYY FineReader for Mac的快速安装
- ejs 文档翻译
- 图片拉伸处理
- Android LayoutInflater详解