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. linux里source、sh、bash、./有什么区别

    在linux里,source.sh.bash../都可以执行shell script文件,那它们有什么不同吗? ----------- 1.source source a.sh 在当前shell内去读 ...

  2. 13-C语言字符串函数库

    目录: 一.C语言字符串函数库 二.用命令行输入参数 回到顶部 一.C语言字符串函数库 1 #include <string.h> 2 字符串复制 strcpy(参数1,参数2); 参数1 ...

  3. Eclipse+ADT的环境搭建

    Index: . Java环境变量的设置 . Android环境变量的设置 1.Java环境变量的设置 A.属性名称:JAVA_HOME 属性值:C:\Program Files\Java\jdk1. ...

  4. 一,PHP 语法

    基本的 PHP 语法 PHP 的脚本块以 <?php 开始,以 ?> 结束.您可以把 PHP 的脚本块放置在文档中的任何位置. 当然,在支持简写的服务器上,您可以使用 <? 和 ?& ...

  5. 使用C#对MongoDB中的数据进行查询,改动等操作

    首先,使用的是官方提供的C#訪问组件https://github.com/mongodb/mongo-csharp-driver 然后.编译后引用MongoDB.Bson.dll及MongoDB.Dr ...

  6. Codeforces 18C C. Stripe

    Codeforces 18C  C. Stripe 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/E 题 ...

  7. HDU 1045(质因数分解)

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Tomor ...

  8. Object lifetime

    Object lifetime Temporary object lifetime Storage reuse Access outside of lifetime Every object has ...

  9. 使用yum来下载RPM包而不进行安装

    1. 安装yum-downloadonly. yum-utils 或 yum-plugin-downloadonly 软件包 (RHEL5) # yum install yum-downloadonl ...

  10. MYSql和PHP计算数据性能

    MYSQL不是有很多内部计算函数吗? 比如我要计算一列数据的平均值,,那我是直接用MYSQL里面的函数在SQL语句中计算 快 :还是用SQL把数据取出来了,用PHP计算快呢?(SQL语句PHP语句都用 ...