HDU 5586 Sum "DP Max Sub-segment and"

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5586Sum

Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 677 Accepted Submission (s): 358


Problem Descriptionthere is a number sequenceA1, a 2 a n , you can select a interval [l,r] or not,all the numbersAi(l≤i≤r) would becomeF(Ai) .F(x)=(1890x+143)mod10007 . After that,the sum of n numbers should is as much as possible. What is the maximum sum?

Inputthere is multiple test cases.
First line of all case contains a single integer n.(1≤n≤5)
Next line contains n integersA1,A2.. . . An .(0≤Ai≤4)
It ' s guaranteed that ∑n≤6.

Outputfor each test case,output the answer in a line.

Sample Input210000 999951 9999 1 9999 1

Sample Output1999922033
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #define MAX 100000#define LL long longusing 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]);//storage f (x);     b[i]=a[i]-s[i];//store f (x) and X difference values     sun+=s[i];    }    int sum=0;    int max=0;    for (i=1;i<=n;i++)//maximum child segment and code     {    if (sum<=0)    sum=b[i]    ; else    Sum+=b[i];    Max=max (max,sum);//Find maximum sub-segment     }    printf ("%d\n", Sun+max);} return 0; }

  

HDU 5586 Sum "DP Max Sub-segment and"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.