HDOJ1003】的更多相关文章

终于开始DP了] HDOJ_1159  Common  Subsequence 题目链接 Sample Input abcfbc abfcab programming contest abcd mnp Sample Output   4   2   0 子结构特征: lf(i,j)=  f(i-1,j-1)+1 (a[i]==b[j]) max(f(i-1,j),f(i,j-1)) (a[i]!=b[j]) 由于f(i,j)只和f(i-1,j-1), f(i-1,j)和f(i,j-1)有关, 而…
HDOJ链接 http://acm.hdu.edu.cn/showproblem.php?pid=1003 不了解题目的朋友可以先看一下题目,在这里就不再详细介绍了.(文章内容和解题思路不完全相同,方法一.二.三.四没有对sequence 全为负数的情况进行考虑,就不再对代码进行更新了,如果需要可看1003解题代码,最下面.) Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a…
http://acm.hdu.edu.cn/showproblem.php?pid=1003 给出一个包含n个数字的序列{a1,a2,..,ai,..,an},-1000<=ai<=1000 求最大连续子段和及其起始位置和终止位置,很基础的动态规划(DP)问题,看完DP第一次做的DP题目 DP真的是一种很优美的算法,或者说思想,但是比较难理解,我对DP的理解还很浅薄 # include <stdio.h> # define INF 1000000000 int main() { i…
#include<iostream> using namespace std; int main() { ],t=,m; cin >> n; while(n--) { cin >> m; ;i<m;i++) cin >> a[i]; ]; ; ; ; ;i<m;i++) { ) summ = summ + a[i]; else summ = a[i]; if (maxu<summ) { maxu = summ; endi = i; } }…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 306494    Accepted Submission(s): 72850 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s…
这道题目的DP,写到现在才明白... 每次加或者不加的条件就是这个前面这个子序列合是不是大于等于0,如果不是加了就会让这个位置的值没有意义,如果大于0,他还是在往递增的方向继续前进. 以及这个条件的继续理解:我想用三个例子 )1:5 -1 -2 -3 )2:5 1 -2 )3:5 -1 -2 1 1 可以试着模拟一下,为什么这个判断条件的正确性 #include <iostream> #include <stdio.h> #include <string.h> #inc…