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. 数据库水平切分的实现原理解析——分库,分表,主从,集群,负载均衡器(转)

    申明:此文为转载(非原创),文章分析十分透彻,已添加原文链接,如有任何侵权问题,请告知,我会立即删除. 第1章 引言 随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大 ...

  2. cocos2d-x Android环境搭建

    1.Java虚拟机.分32位和64位.64位: jdk-8u11-windows-x64-8.0.11.12.1406275777 环境变量配置,我的电脑右击->属性->高级系统设置-&g ...

  3. C++模板:ST算法

    //初始化 void init_rmq(int n){ for(int i=0;i<n;i++)d[i][0]=a[i]; for(int j=1;(1<<j)<=n;j++) ...

  4. 实现最小宽度的几种方法及CSS Expression[转]

    实现最小宽度的几种方法及CSS Expression[转] 实现最小宽度的几种方法:css表达式尽量不用 支持FF IE7  IE6 .test { background:blue; min-widt ...

  5. 3027 - Corporative Network(并差集)

    3027 - Corporative Network A very big corporation is developing its corporative network. In the begi ...

  6. 编写可维护的JavaScript—语句和表达式&变量、函数和运算符

    语句和表达式 所有的块语句都应当使用花括号.包括: if for while do…while… try…catch…finally //不好的写法 if (condition) doSomethin ...

  7. DevExpress ASP.NET 使用经验谈(6)-ASPxGridView属性设置与CRUD界面优化

    上一节中,我们通过简单的配置,通过ASPxGridView控件的使用,完成了对数据库表的CRUD操作. 这样的界面展现,功能是达到了,但是操作体验上,还是有所欠缺的. 图一 默认生成的列表界面 图二 ...

  8. How Many Answers Are Wrong(并查集)

    Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he ...

  9. Hibernate之工具类HibernateUtil

    原创文章,转载请注明:Hibernate之工具类HibernateUtil  By Lucio.Yang 1.最简单的工具类,实现SessionFactory的单例共享,session的管理 pack ...

  10. 64位win8 配置Apache2.4+mod_msgi4.4.21+django1.8.6+python3.4

    学习了很多前人分享的资料,整理如下: 安装步骤: 一.安装python3.4        下载 python-3.4.3.amd64.msi 直接安装         地址:https://www. ...