UESTC 2015dp专题 E 菲波拉契数制 dp
菲波拉契数制
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/65
Description
我们定义如下数列为菲波拉契数列:
F(1)=1
F(2)=2
F(i)=F(i−1)+F(i−2)(i>=3)
给定任意一个数,我们可以把它表示成若干互不相同的菲波拉契数之和。比如13有三种表示法
13=13
13=5+8
13=2+3+8
现在给你一个数n,请输出把它表示成若干互不相同的菲波拉契数之和有多少种表示法。
wij 千 克的蛋糕,Gorwin从左上角(1,1)的格子开始走,走到右下角(n,m)的格子。在每一步中,Gorwin可以向右或者向下走,即是:Gorwin 站在(i,j)的时候,她可以走向(i+1,j)或者(i,j+1) (然而她不能走出这个花园)。 当Gorwin到达一个格子的时候,她可以把那个格子里面的蛋糕吃完或者不吃。但是,她不能只吃一部分。她的胃不是那么大,所以她最多只能吃K千克的蛋 糕。现在,Gorwin站在左上角,她在看蛋糕园的地图,想要找出一条路,能够使得她吃到的蛋糕最多的一条路。请你来帮帮忙。
Input
第一样一个数T,表示数据组数,之后T行,每行一个数n。
T≤105
1≤n≤105
Output
输出T行,每行一个数,即n有多少种表示法。
Sample Input
Sample Output
1 1 2 1 2 3
HINT
题意
题解:
其实这道题是dp,转化成2进制做
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
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;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll fib[maxn];
int topf;
vector<int> vec;
void init()
{
int i;
fib[]=fib[]=;
for (i=;fib[i-]<1000000000000000000LL;i++)
{
fib[i]=fib[i-]+fib[i-];
}
topf=i-;
}
ll f[maxn][];
int a[maxn];
ll n,m;
int main()
{
int i,j,k;
int x,y,z;
int nn;
scanf("%d",&nn);
init();
while (nn--)
{
n=read();
vec.clear();
for (i=topf;i>;i--)
{
if (fib[i]<=n)
{
n-=fib[i];
vec.push_back(i);
}
}
sort(vec.begin(),vec.end());
for (i=;i<vec.size();i++)
{
a[i]=(-((i)?vec[i-]:)+vec[i]);
}
f[][]=;
f[][]=a[]/;
for (i=;i<vec.size();i++)
{
f[i][]=((a[i]-)/)*f[i-][]+((a[i])/)*f[i-][];
f[i][]=f[i-][]+f[i-][];
}
printf("%lld\n",f[vec.size()-][]+f[vec.size()-][]);
}
return ;
}
UESTC 2015dp专题 E 菲波拉契数制 dp的更多相关文章
- Contest20140906 ProblemC 菲波拉契数制 DP
C.菲波拉契数制时间:2s 内存:65536KB我们定义如下数列为菲波拉契数列: F (1) = 1 F (2) = 2 ...
- UESTC_菲波拉契数制升级版 2015 UESTC Training for Dynamic Programming<Problem L>
L - 菲波拉契数制升级版 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Su ...
- UESTC_菲波拉契数制 2015 UESTC Training for Dynamic Programming<Problem E>
E - 菲波拉契数制 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- [dp]uestc oj E - 菲波拉契数制
E - 菲波拉契数制 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- CDOJ 1133 菲波拉契数制 变直接统计为构造
菲波拉契数制 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit St ...
- [dp][uestc]L - 菲波拉契数制升级版
数据很大,以背包的思路数组开不下. 先定序地考虑一个菲波拉契数如fib(i)的表示法,假设i比较大,由菲波拉契数的定义可知道fib(i)=fib(i-1)+fib(i-2);要找到其它表示就继续拆分f ...
- 递归函数练习:输出菲波拉契(Fibonacci)数列的前N项数据
/*====================================================================== 著名的菲波拉契(Fibonacci)数列,其第一项为0 ...
- e8_4输出菲波拉契数列的前10项
program fbnq;{输出菲波拉契数列的前10项} var a:..] of integer; i:integer; begin a[]:=; a[]:=; do a[i]:=a[i-]+a[i ...
- C语言-郝斌笔记-005菲波拉契序列
菲波拉契序列 /* 菲波拉契序列 1 2 3 5 8 13 21 34 */ # include <stdio.h> int main(void) { int n; int f1, f2, ...
随机推荐
- PHP深浅拷贝
举个栗子: <?php class Example1 { public $name; public function __construct($name) { $this->name = ...
- module 'pytest' has no attribute 'allure'问题解决
安装allure后执行命令后报错module 'pytest' has no attribute 'allure' C:\Users\Desktop\xin>pytest -s -q --all ...
- C++随笔(2)
在牛客网上刷题,遇到的一些需要注意的题 1.这题需要注意的是strcpy复制的时候什么时候停止 2.这题是关于strlen的,它不统计‘\0',但复制的时候仍会复制. 3.这题是写strcpy函数的, ...
- oracle 一个网站
http://www.oracle.com/technetwork/cn/articles/11g-pivot-101924-zhs.html
- touch命令的用法
touchtouch 文件,如果文件不存在,则创建一个新文件:如果文件存在,则将该存在的文件的修改时间或创建时间改为当前时间touch -t 时间戳 文件,则把该文件的时间改了
- 面试题12:打印1到最大的n位数(大数问题)
面试题是关于n位整数并且没有限定n的取值范围,或者是输入任意大小的整数,那么这个题目就很可能需要考虑大数问题.字符串是一个简单的.有效的表示大数的方法 这题比较难,用递归表达全排列,数字每一位都可能是 ...
- 监控属性数组(Observables Arrays )
如果你想发现并响应一个对象的改变,就应该用监控属性(observables).如果你想发现并响应一个集合的变化,就该用监控属性数组 (observableArray).监控属性数组在显示或编辑多个值以 ...
- logstash收集nginx日志
(1)安装nginx 1.安装nginx yum install epel-release -y yum install nginx -y 2.修改日志文件格式为json #vim /etc/ngin ...
- Linux内存管理中的slab分配器
转载自:http://edsionte.com/techblog/archives/4019 Linux内核中基于伙伴算法实现的分区页框分配器适合大块内存的请求,它所分配的内存区是以页框为基本单位的. ...
- Sharepoint 2010 TimerJob重复
昨天被TimerJob困扰了一天.原因就是TimerJob当中会有一个Httpwebrequest GET请求一个Application Page进行一些操作(其中有一个操作是发送邮件).但是发现随机 ...