Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:还是递归的DP的好写

Posted by NetWilliam at 2020-03-28 09:26:53 on Problem 3186
In Reply To:还是递归的DP的好写 Posted by:dongshanluo at 2009-06-07 23:47:06
> dp[i][j]表示只有[i,j]这一连续区间的长度cows时可以得到的最大利润,
> 显然,当i=j时dp[i][j] = v[i];
> i!=j时:
> dp[i][j] = max(v[j]+dp[i+1][j]+sum[j]-sum[i],dp[i][j-1]+v[j]+sum[j-1]-sum[i-1])
> 
> 这个方程的意思是,对于这里的连续区间[i,j],必定有i或者j是先被卖出去的
> 上述方程整理一下就是
> dp[i][j] = max(dp[i+1][j],d[i][j-1]) + sum[j]-sum[i-1];
> 
> 其中sum[i] = v[1]+v[2]+...v[i];

你这个做法很漂亮, 我算 sum(j, i-1) 用二维数组缓存会tle, 但是用你这个sum[i] 数组做法就ac了, 谢谢你的分享, 给我很大的启发

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator