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"