Hdu 5586 Sum

Sum

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

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

 

Source

BestCoder Round #64 (div.2)

 

题目大意:

给n个数{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,你可以选择一个区间(也可以不选),区间里每个数x变成f(x),其中f(x)=(1890x+143) mod 10007f(x)=(1890x+143)mod10007。问最后n个数之和最大可能为多少。

解题思路:

就是比较一下大小就行了,但是是减去arr[i]的值。。。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e5+5;
const int mod = 1e4+7;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
LL gcd(LL a, LL b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}
int arr[maxn], data[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        LL sum = 0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&arr[i]);
            sum += arr[i];
            data[i] = ((arr[i]*1890+143)%mod) - arr[i];
        }
        LL Max = 0, tmp = 0;
        for(int i=0; i<n; i++)
        {
            tmp += data[i];
            if(tmp > Max)
                Max = tmp;
            if(tmp < 0)
                tmp = 0;
        }
        LL ret = sum+Max;
        printf("%I64d\n",ret);
    }
    return 0;
}
时间: 2024-11-03 21:01:41

Hdu 5586 Sum的相关文章

HDU 1024Max Sum Plus Plus(最大m字段和)

/* 动态转移方程:dp[i][j]=max(dp[i-1]+a[i], max(dp[t][j-1])+a[i]) (j-1<=t<i) 表示的是前i个数j个字段和的最大值是多少! */ #include<iostream> #include<cstdio> #include<cstring> #define N 10000 using namespace std; int dp[N][N], num[N]; int main() { int n, m,

hdu 4430 Yukari&#039;s Birthday

点击打开链接hdu 4430 思路:枚举r+二分k 分析: 1 题目要求的是找到一组最小的r*k,如果r*k相同那么就找r最小的. 2 很明显k>=2,根据n <= 10^12,那么可以知道r的最大值r<50,所以只要枚举枚举r的值,然后二分k的大小找到所有的解,存入一个结构体里面,然后在对结构体排序,那么这样就可以得到最后的ans 3 注意题目说了中心点最多一个蜡烛,所以写二分的时候应该注意判断的条件: 4 还有可能计算得到结果超了long long直接变成负数所以应该对或则个进行判断

hdu 5280 Senior&amp;#39;s Array

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5280 问题描述 某天学姐姐得到了一个数组A ,在这个数组的所有非空区间中,她找出了一个区间和最大的,并把这个区间和定义为这个数组的美丽值. 但是她觉得这个数组不够美,于是决定修理一下这个数组. 学姐姐将会进行一次操作,把原数组中的某个数修改为P (必须修改). 最后她想使得修改后的数组尽可能美丽.请你帮助她计算经过修理后,这个数组的美丽值最大能是多少? #include <iostream> #i

HDU 2985 Another lottery(水题)

HDU 2985:http://acm.hdu.edu.cn/showproblem.php?pid=2985 大意: 给你n个人,每个人买m次彩票,第i次的奖金是2的i次方,求每个人赢的比其他人都多的可能性是多少. 思路: 就是只看最后一次就行,2的i次方,对于每个人来说,最后一次的奖要比前面的大很多,所以直接只看最后一次,算出概率gcd一下就行了. 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ #i

HDU 3501 Calculation 2:欧拉函数的应用

HDU 3501 Calculation 2:http://acm.hdu.edu.cn/showproblem.php?pid=3501 大意:求1~n之间与n不互质的数的总和. 思路:欧拉函数的应用:先用欧拉函数求出与n互质的总数m,计算m个数的总和,用n的总和减去m的总和就是想要的结果. 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ #include <stdio.h> #define LL _

HDU 3038 How Many Answers Are Wrong? :带权并查集

链接: http://acm.hdu.edu.cn/showproblem.php?pid=3038 题目: Problem Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. T

HDU 1535 Invitation Cards:多源点到单点最短路

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 题目: Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1044    Accepted Submission(s): 459 Problem Description In the age of te

HDU 2923 Einbahnstrasse

链接: http://acm.hdu.edu.cn/showproblem.php?pid=2923 题目: Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1117    Accepted Submission(s): 31 Problem Description Einbahnstra You just started a new

HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1839 题目: Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 226    Accepted Submission(s): 98 Problem Descri