http://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; int maxsum(int arr[], int n) {
int insum = arr[];
int exsum = ;
for (int i = ; i < n; i++) {
int tmp = max(insum, exsum);
insum = exsum + arr[i];
exsum = tmp;
}
return max(insum, exsum);
} int main() {
int arr[] = {, , , , , };
cout << maxsum(arr, ) << endl;
return ;
}

Data Structure Array: Maximum sum such that no two elements are adjacent的更多相关文章

  1. Data Structure Array: Maximum circular subarray sum

    http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...

  2. Data Structure Array: Maximum of all subarrays of size k

    http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/ #include <iostream> #include ...

  3. Data Structure Array: Find if there is a subarray with 0 sum

    http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...

  4. Data Structure Array: Given an array arr[], find the maximum j – i such that arr[j] > arr[i]

    http://www.geeksforgeeks.org/given-an-array-arr-find-the-maximum-j-i-such-that-arrj-arri/ #include & ...

  5. Data Structure Array: Find the Missing Number

    http://www.geeksforgeeks.org/find-the-missing-number/ 1. use sum formula, O(n), O(1) 2. use XOR, O(n ...

  6. Data Structure Array: Largest subarray with equal number of 0s and 1s

    http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/ #include <iostream& ...

  7. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  8. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...

  9. Data Structure Array: Sort elements by frequency

    http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...

随机推荐

  1. Android 报错记录

     IOException java.io.IOException: Permission denied: 权限不足.原因可能是: 未加入权限 <uses-permission android ...

  2. ClassLibary和WPF User Control LIbary和WPF Custom Control Libary的异同

    说来惭愧,接触WPF这么长时间了,今天在写自定义控件时遇到一个问题:运行界面中并没有显示自定义控件,经调试发现原来没有加载Themes中的Generic.xaml. 可是为什么在其他solution中 ...

  3. Spring学习二----------IOC及Bean容器

    © 版权声明:本文为博主原创文章,转载请注明出处 接口 用于沟通的中介物的抽象化 实体把自己提供给外界的一种抽象化说明,用以由内部操作分离出外部沟通方法,使其能被修改内部而不影响外界其他实体与其交互的 ...

  4. lua学习笔记(四)

      表达式   算术操作符     +(加法) -(减法) *(乘法) /(除法) ^(指数) %(取模) -(负号)     x%1的结果是x的小数部分,x-x%1是整数部分   关系操作符     ...

  5. Redis用LPUSH和RPOP实现消息队列

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using ServiceS ...

  6. 跟我一起写 Makefile(三)[转]

    原文链接 http://bbs.chinaunix.net/thread-408225-1-1.html(出处: http://bbs.chinaunix.net/) make 的运行—————— 一 ...

  7. 刷脸支付真的来啦!华为nova3带你玩转酷时代~

    无论是不愿脱离手套的怕冷手. 或是沾满泥土芬芳的勤劳手. 还是挂着水滴的清洁手…… 每当这些时刻,打开支付宝认证支付, 指纹解锁的能力总是光彩尽失. 不过,就在华为nova 3的发布会上, 一项传说已 ...

  8. window 杀死已开任务启命令

    1. 查询已开启的端口号 C:\Users\Administrator>netstat -ano | findstr 如果被占用会查询出相关信息,如果没有被占用则不会输出任何信息,查询到已开启信 ...

  9. SVN版本号控制软件-图片含义具体解释

    转载请注明出处:http://blog.csdn.net/zhuwentao2150/article/details/51195154 自己定义SVN图标显示风格 SVN的图标是能够自己定义风格的 右 ...

  10. PHP-Manual的学习----【语言参考】----【类型】-----【对象】

    Object 对象1.对象初始化要创建一个新的对象 object ,使用 new 语句实例化一个类: class foo{    function do_foo(){        echo &quo ...