Consider the sequence of numbers aii = 0, 1, 2, …, which satisfies the following requirements:

  • a0 = 0
  • a1 = 1
  • a2i = ai
  • a2i+1 = ai + ai+1

for every i = 1, 2, 3, … .

Write a program which for a given value of n finds the largest number among the numbers a0a1, …,an.

Input

You are given several test cases (not more than 10). Each test case is a line containing an integern (1 ≤ n ≤ 99 999). The last line of input contains 0.

Output

For every n in the input write the corresponding maximum value found.

Sample

input output
5
10
0
3
4
Problem Author: Emil Kelevedzhiev
Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament
// Ural Problem 1079. Maximum
// Verdict: Accepted
// Submission Date: 14:33:08 15 Jan 2014
// Run Time: 0.031s
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/// [解题方法]
// 简单题模拟题
// 注意:最大项有可能是奇数项 #include<stdio.h> long long a[], b[]; void solve()
{
int i, j, max, n;
a[] = b[] = ;
a[] = b[] = ;
max = ;
for(i = ; i < ; i++) {
if(i % ) {
j = (i - ) >> ;
a[i] = a[j] + a[j + ];
} else {
a[i] = a[i >> ];
}
if(a[i] > max)
max = a[i];
b[i] = max;
}
while(scanf("%d", &n) && n) {
printf("%lld\n", b[n]);
}
} int main()
{
solve();
return ;
}

Ural 1079 - Maximum的更多相关文章

  1. 最大子矩阵和 URAL 1146 Maximum Sum

    题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> ...

  2. ural 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...

  3. URAL 1146 Maximum Sum(最大子矩阵的和 DP)

    Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...

  4. ural 1146. Maximum Sum(动态规划)

    1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...

  5. URAL 1146 Maximum Sum(DP)

    Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...

  6. URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)

    点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...

  7. URAL 1146 Maximum Sum 最大子矩阵和

    题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...

  8. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  9. 1042 数字0-9的数量 1050 循环数组最大子段和 1062 序列中最大的数 1067 Bash游戏 V2 1092 回文字符串

    1042 数字0-9的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 给出一段区间a-b,统计这个区间内0-9出现的次数.   比如 10-19,1出现11次 ...

随机推荐

  1. codeforcese 498C. Array and Operations 网络流

    题目链接 给n个数, m个数对, 每个数对是两个下标加起来为奇数的两个数.每次操作可以使一个数对中的两个数同时除某个数, 除的这个数是这两个数的任意约数, 问这种操作最多可以做几次.n<100, ...

  2. Ubuntu 12.04中文输入法的安装(转)

    Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu的中文系统中自带了中文输入法,通过Ctrl+S ...

  3. 安装VMware vSphere 的目的就是在一台物理服务器上安装很多很多的虚拟机

    版权声明:本文为博主原创文章,未经博主允许不得转载. 我们安装VMware vSphere 的目的就是在一台物理服务器上安装很多很多的虚拟机,我们可以通过VMware vSphere Client直接 ...

  4. C#)Windows Shell 编程系列5 - 获取图标

    原文 C#)Windows Shell 编程系列5 - 获取图标 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 编程系列4 - 上下 ...

  5. Android 百度地图开发问题----解决地图有时候加载不出来问题

    相信很多人在开发百度地图的时候会出现百度地图有时候会加载不出来,只显示网格图. 这个问题究其原因就是申请百度key的时候填写的SHA1也就是指纹证书有问题.估计很多开发者都是照着百度开放平台上介绍的流 ...

  6. python+opencv

    $cd numpy $ sudo python setup.py build $ sudo python setup.py installRunning from numpy source direc ...

  7. 宣布正式发布 Windows Azure 上的 Oracle 软件以及 Windows Azure Traffic Manager 更新

     Windows Azure 的核心原则之一就是为客户提供一个开放.灵活的平台.今天是一个令人振奋的里程碑,因为我们与 Oracle 的合作又向前迈进了一步.Oracle Database.Ora ...

  8. Sublime Text 2 - There are no packages available for installation

    解决Sublime Text 2 package Control 无法安装插件的问题 错误提示 here are no packages available for installation 问题解决 ...

  9. XML和DTD的简单介绍和入门

    XML(Extensible Markup Lanaguage),可扩展标记语言,是标准通用标记语言(Standard Generalized Markup Language, SGML)的一个子集, ...

  10. json数据的获取(网络摘抄)

    一个简单的对象: $.ajax({ type: "post", url: "Handler.ashx", dataType: "html", ...