码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ:5586

时间:2015-12-04 12:16:08      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

Problem Description
There is a number sequence A技术分享1技术分享,A技术分享2技术分享....A技术分享n技术分享技术分享 ,you can select a interval [l,r] or not,all the numbers A技术分享i技术分享(lir)技术分享 will become f(A技术分享i技术分享)技术分享 .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.(1n10技术分享5技术分享)技术分享
Next line contains n integers A技术分享1技术分享,A技术分享2技术分享....A技术分享n技术分享技术分享 .(0A技术分享i技术分享10技术分享4技术分享)技术分享
It‘s guaranteed that n10技术分享6技术分享技术分享 .
 

 

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<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
  int n;
  int a[100010],b,c[100010];
  int i,sum,count;
  while(scanf("%d",&n)!=EOF)//多组测试数据
  {
    sum=0;
    for(i=0;i<n;i++)
    {
      cin>>a[i];
      b=(1890*a[i]+143)%10007;
      c[i]=b-a[i];//子序列
      sum+=a[i];//原序列的和
    }


    for(i=1;i<n;i++)
    {
      c[i]=max(c[i],c[i-1]+c[i]);   
    }//动态规划求最大子序列的和

    count=0;
    for(i=0;i<n;i++)
    {
    if(count<=c[i])
      count=c[i];
    }

  printf("%d\n",sum+count);
  }
return 0;
}

 

HDOJ:5586

标签:

原文地址:http://www.cnblogs.com/xiangrutt/p/5018638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!