HDU 5586 (dp 思想)

Sum

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

Problem Description

There is a number sequence A1,A2....An

,A1,A2....An

,A1,A2....An

,A1,A2....An

,A1,A2....An

,A1,A2....An

,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)

传送门 http://acm.hdu.edu.cn/showproblem.php?pid=5586

类似杭电1003

题意  一串序列 可以只能更改一个区间 或不更改f(x)=(1890x+143)mod10007    更改操作为f(x)=(1890x+143)mod10007

询问 这串序列的和的最大值

做一个变形 每个值变为 f(x)-x 然后按照1003的方法 求最大连续区间的和

dp[i]=max(dp[i],dp[i-1]+dp[i]);

f(x)=(1890x+143)mod10007

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
int bac(int s)
{
    return (1890*s+143)%10007;
}
int b[100005],a[100005];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(b,0,sizeof(b));
        memset(a,0,sizeof(a));
        int re=0;
        for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
                re=re+a[i];
                b[i]=bac(a[i])-a[i];
            }
          //  int exm=0;
            int maxn=0;
          for(int i=1;i<n;i++)
          {
              if(b[i]+b[i-1]>b[i])
                b[i]=b[i]+b[i-1];
       if(b[i]>maxn)
                     maxn=b[i];

          }
        printf("%d\n",re+maxn);
    }
    return 0;
}
时间: 2024-08-25 15:30:14

HDU 5586 (dp 思想)的相关文章

hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)

Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 481    Accepted Submission(s): 245 Problem Description You were driving along a highway when you got caught by the road p

hdu 4105 贪心思想

淋漓尽致的贪心思想 波谷一定是一位数,波峰一位数不够大的时候添加到两位数就一定够大了的. 当在寻找波谷碰到零了就自然当成波谷. 当在寻找波峰时碰到零时,将前面的波谷加到前一个波峰上,让当前的零做波谷,使得波谷的值尽量小,这就是本题最关键的贪心思想,一直想不到. 代码中:a表示前一个值,b表示当前考虑的值,tag为偶数时表示正在寻找波谷,奇数时在寻找波峰. #include<iostream> #include<cstdio> #include<cstring> #inc

HDU 4832(DP+计数问题)

HDU 4832 Chess 思路:把行列的情况分别dp求出来,然后枚举行用几行,竖用几行,然后相乘累加起来就是答案 代码: #include <stdio.h> #include <string.h> #include <iostream> using namespace std; typedef long long ll; const ll MOD = 9999991; const int N = 1005; int t, n, m, k, x, y; ll dp1

hdu 3944 dp?

DP? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 128000/128000 K (Java/Others)Total Submission(s): 1804    Accepted Submission(s): 595 Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0,1,2,-a

hdu 5389 dp类似背包

http://acm.hdu.edu.cn/showproblem.php?pid=5389 Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft. Stilwell is enjoying the first chapter of this

DP思想在斐波那契数列递归求解中的应用

斐波那契数列:1, 1, 2, 3, 5, 8, 13,...,即 f(n) = f(n-1) + f(n-2). 求第n个数的值. 方法一:迭代 public static int iterativeFibonacci(int n) { //简单迭代 int a = 1, b = 1; for(int i = 2; i < n; i ++) { int tmp = a + b; a = b; b = tmp; } return b; } 方法二:简单递归 public static long

hdu 1025 dp 最长上升子序列

1 //Accepted 4372 KB 140 ms 2 //dp 最长上升子序列 nlogn 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 using namespace std; 7 const int imax_n = 500005; 8 int dp[imax_n]; 9 int d[imax_n]; 10 int a[imax_n]; 11 int n; 12 int len

HDU 5928 DP 凸包graham

给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也就是 dp[j][k]代表当前链末端为j,其内部点包括边界数量为k的最小长度.这样最后得到的一定是最优的凸包. 然后就是要注意要dp[j][k]的值不能超过L,每跑一次凸包,求个最大的点数量就好了. 和DP结合的计算几何题,主要考虑DP怎么搞 /** @Date : 2017-09-27 17:27

HDU 4901 DP背包

给你n个数,问你将数分成两个数组,S,T ,T 中所有元素的需要都比S任意一个大,问你S中所有元素进行 XOR 操作和 T 中所有元素进行 &操作值相等的情况有多少种. DP背包思路 dpa[i][j][0]  表示从左开始到i,不取i,状态为j的方案数 dpa[i][j][1]  表示从作开始到i,取i,状态为j的方案数 dpb[i][j]      表示从右开始到i,状态为j的方案数 因为S集合一定在T集合的左边,那么可以枚举集合的分割线,并且枚举出的方案要保证没有重复,如果要保证不重复,只