题目链接: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. HDU2110+母函数

    /* 母函数(生成函数) 题意: 有n种资产,每种资产num份,每份有val的价值 问取出总价值的1/3有多少种方案 */ #include<stdio.h> #include<st ...

  2. SSH hibernate 使用时最好添加访问数据库的编码

    SSH hibernate 使用时最好添加访问数据库的编码 如下所示:第13行为设置hibernate访问数据库的编码(&是&的转义序列) <!DOCTYPE hibernate ...

  3. HTTPS访问:weblogic下配置SSL

    进入Weblogic安装路径下的JDK安装目录bin文件下,通过keytool工具生成密钥对(标识密钥库) 输入命令,生成密钥 keytool.exe -genkey -v -alias weblog ...

  4. [itint5]任务调度

    http://www.itint5.com/oj/#10 拓扑排序.首先按照题目给出的数据结构复杂度不会是O(v+e)的,所以先要变换数据结构.二来写的时候用一个stack会更好点.还有就是题目里其实 ...

  5. 【调侃】IOC前世今生 工厂模式 反射 依赖倒置

    http://www.cnblogs.com/showjan/p/3950989.html

  6. Android:实现无标题的两种方法

    实现无标题的两种方法:配置xml文件和编写代码设置 1.在AndroidManifest.xml文件中进行配置 实现全屏效果: android:theme="@android:style/T ...

  7. Linux下实现C++类的动态链接

    1. 背景 在java中,jvm支持类的动态链接(Class.forName(String className)),用起来也很方便.动态链接是实现IOC(Inversion of Control,控制 ...

  8. The document has been modified outside of Code Composer. Would you like to reload the file

    2013-06-20 10:03:32 烧写过程是合众达给出的文档 problem: I'm new to using Code Composer Studio 3.3 and am having a ...

  9. 转 Android adb root权限

    永久root带文件 因为开发需要,我经常会用到adb这个工具(Android Debug Bridge),我们都知道adb shell默认是没有root权限的,修改系统文件就很不方便了,adb pus ...

  10. [转]jBoss事务控制

    转自:http://blog.csdn.net/trendgrucee/article/details/8545512   一.基础知识 1.JTA,即Java Transaction API,译为J ...