动态规划 is beginning。。。。。。。。。

感觉动态规划很模糊,怎么办呢???

狂刷题吧!!!!!!!!!!!!!!!!!!!!!!!!!

1.POJ 2479 Maximum sum

首刷水题!!!!

双向统计最大和。

AC代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#define inf -1000000000
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        int i;
        scanf("%d",&n);
        int a[50005],dp[50005];
        memset(dp,0,sizeof dp);
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int sum=0;
        int maxx=inf;//需要取到负最小
        for(i=1;i<n;i++)
        {
            sum+=a[i];
            if(sum>maxx)
                maxx=sum;
            dp[i]=maxx;
            if(sum<0)
                sum=0;
        }
        int ans=inf;maxx=inf;sum=0;
        for(i=n;i>1;i--)
        {
            sum+=a[i];
            if(sum>maxx)
                maxx=sum;
            ans=max(ans,maxx+dp[i-1]);
            if(sum<0)
                sum=0;
        }
        cout<<ans<<endl;
    }
    return 0;
}

动态规划 is beginning。。。。。。。。。

时间: 2024-10-08 03:06:50

动态规划 is beginning。。。。。。。。。的相关文章

VF(动态规划)

VF 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as Pythagor

HDU 5009 Paint Pearls (动态规划)

Paint Pearls Problem Description Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper and asks for your help. In eac

动态规划中转移方程的一个技巧

动态规划是一个很神奇的东西,总结一下自己写动态规划是的一些盲区! 有时候在定义状态的时候,可以用一定的方法,可以达到对转移时的时间复杂度起到很大的优化作用,以下面的题目来说明这点. Writing Code Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, t

_____________________________________动态规划之最长子序列问题______1:两个序列中的______________________________________

动态规划之最长自序列问题....两个字符串中的最长子序列问题. 参考例题杭电1159.....参考文件.lcy老师的课件....在此对lcy老师致敬.. 最长子序列问题....... 下面附上题目 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Hand Online Acmers Forum | Discuss Statistical Charts Proble

UVA - 147 - Dollars (集合上的动态规划)

UVA - 147 Dollars Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will

HDU-1159 Common Subsequence(动态规划2)

Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there exists a strictly

[动态规划]Milking Time

Milking Time TimeLimit: 1000ms  MemoryLimit:65536KB 64-bit integer IO format:%lld Problem Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,

[ACM] POJ 2677 Tour (动态规划,双调欧几里得旅行商问题)

Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3585   Accepted: 1597 Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must

HDU 1159 Common Subsequence (动态规划、最长公共子序列)

Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 55301    Accepted Submission(s): 25537 Problem Description A subsequence of a given sequence is the given sequence with some el