题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586

Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 677    Accepted Submission(s):
358

Problem Description
There is a number sequence A1,A2....An

,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r)

will become f(Ai)

.f(x)=(1890x+143)mod10007

.After that,the sum of n numbers should be as much as possible.What is the
maximum sum?

 
Input
There are multiple test cases.
First line of each
case contains a single integer n.(1≤n≤105)

Next line contains n integers A1,A2....An

.(0≤Ai≤104)

It's guaranteed that ∑n≤106

.

 
Output
For each test case,output the answer in a
line.
 
Sample Input
2
10000 9999
5
1 9999 1 9999 1
 
Sample Output
19999
22033
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 100000
#define LL long long
using namespace std;
LL fun(LL x)
{
return ((1890*x)%10007+143%10007)%10007;
}
int main()
{
int n,m,j,i,k;
int s[MAX],a[MAX],b[MAX];
while(scanf("%d",&n)!=EOF)
{
int sun=0;
for(i=1;i<=n;i++)
{
scanf("%d",&s[i]);
a[i]=fun(s[i]);//储存 f(x);
b[i]=a[i]-s[i];//储存f(x)和x的差值
sun+=s[i];
}
int sum=0;
int Max=0;
for(i=1;i<=n;i++)//最大子段和代码
{
if(sum<=0)
sum=b[i];
else
sum+=b[i];
Max=max(Max,sum);//求出最大子段
}
printf("%d\n",sun+Max);
}
return 0;
}

  

hdu 5586 Sum【dp最大子段和】的更多相关文章

  1. hdu 5586 Sum 最大子段和

    Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 Desc ...

  2. hdu 5586 Sum 基础dp

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...

  3. hdu 5586 Sum(dp+技巧)

    Problem Description There )mod10007.After that,the sum of n numbers should be as much as possible.Wh ...

  4. POJ2479 Maximum sum[DP|最大子段和]

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39599   Accepted: 12370 Des ...

  5. hdu 5586 sum

    Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,al ...

  6. HDU - 5586 Sum(区间增量最大)

    题意:将数组A的部分区间值按照函数f(Ai)=(1890*Ai+143)mod10007修改值,区间长度可以为0,问该操作后数组A的最大值. 分析:先求出每个元素的增量,进而求出增量和.通过b[r]- ...

  7. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  8. HDU 2836 (离散化DP+区间优化)

    Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...

  9. hdu 3507 斜率dp

    不好理解,先多做几个再看 此题是很基础的斜率DP的入门题. 题意很清楚,就是输出序列a[n],每连续输出的费用是连续输出的数字和的平方加上常数M 让我们求这个费用的最小值. 设dp[i]表示输出前i个 ...

随机推荐

  1. 使用IDEA自带maven建java项目时报错。

    今天用IDEA建立maven项目时报错: [INFO] Scanning for projects... [INFO] Searching repository for plugin with pre ...

  2. MVC 国内架构设计

    http://www.cnblogs.com/guomingfeng/p/mvc-ef-query.html http://www.cnblogs.com/haogj/p/3127795.html

  3. Microsoft SQL Server 2012 数据库安装图解教程

    本文部分引用以下文章: SQL Server 2012 安装图解教程(附sql2012下载地址)_MsSql_脚本之家 http://www.jb51.net/article/36049.htm SQ ...

  4. SwapEffect 枚举(定义交换效果)

    由于创建设备时要用到这个值,所以在这里总结一下,以免以后再找. 首先引自msdn: Copy 只能为构成单个后台缓冲区的交换链指定此交换效果. 无论交换链是有窗口的还是全屏的,运行库都保证 Devic ...

  5. Python之函数篇

    函数形参 函数取得的参数是你提供给函数的值,这样函数就可以利用这些值 做 一些事情.这些参数就像变量一样,只不过它们的值是在我们调用函数的时候定义的,而非在函数本身内赋值. 参数在函数定义的圆括号对内 ...

  6. Why it is good practice to declare loggers private, static, and final?

    // Jakarta Commons Loggingprivate static final Log log = LogFactory.getLog(MyClass.class);The above ...

  7. COM, COM+ and .NET 的区别

    所有的优秀程序员都会尽自己的最大努力去使自己所写的程序具有更好的可重用性,因为它可以让你快速地写出更加健壮和可升级性的程序. 有两种使代码重用的选择: 1.白盒:最简单的一种,就是把你的程序片拷贝到另 ...

  8. VS2005下开发PPC2003和WM50编译器一些设置

    1.vs2005开发WM5时,编译器和linker的选项配合问题 链接:http://www.mivi.name/blog/index_en.php?itemid=258 首先说ARM4 ARM4T ...

  9. shorter concat [reverse longer]

    shorter concat [reverse longer] Description: Given 2 strings, a and b, return a string of the form:  ...

  10. Hibernate数据库持久层框架

    Hibernate是一种Java语言下的对象关系映射解决方案. 它是使用GNU宽通用公共许可证发行的自由.开源的软件.它为面向对象的领域模型到传统的关系型数据库的映射,提供了一个使用方便的框架.Hib ...