hdu 1024 Max Sum Plus Plus 最大m个子序列
2017-09-06 18:27
453 查看
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1024
题意
最大m个子序列
dp
dp[divid][now] = max(dp[divid-1][1~now-1], dp[divid-1][now-1])+array[now];
解释:
now 是选择第 now 个, divid 是前 now 个分为 divid 个序列.
数据范围 1e6
dp[1e6][1e6] == mle
降维
降维真不是人干的活2333333
发现每一个元素只用了几次, 有贡献的永远是最大值, 所以开个tmax记录当前divid的max, 滚动下
不清楚为啥divid = 1 的时候会wa, 大概是写挫了, 懒得改于是divid = 1 特判好了
2017-09-06
题意
最大m个子序列
dp
dp[divid][now] = max(dp[divid-1][1~now-1], dp[divid-1][now-1])+array[now];
解释:
now 是选择第 now 个, divid 是前 now 个分为 divid 个序列.
数据范围 1e6
dp[1e6][1e6] == mle
降维
降维真不是人干的活2333333
发现每一个元素只用了几次, 有贡献的永远是最大值, 所以开个tmax记录当前divid的max, 滚动下
不清楚为啥divid = 1 的时候会wa, 大概是写挫了, 懒得改于是divid = 1 特判好了
#include <stdio.h> #include <iostream> #include <cstring> using namespace std; const int MAX = 1e6+10; const long long INF = 1e15+10; long long dp[MAX], ary[MAX], n, m, itor, tmax, nxt, last, ans; long long mmax (long long a, long long b) { return a > b ? a : b; } bool getin() { if (scanf("%lld%lld", &m, &n) == 2) { for (int i = 0; i < n; ++i) scanf("%lld", ary+i); memset (dp, 0, sizeof(dp)); return true; } return false; } void judge() { for (int divid = 1; divid <= m; ++divid) { for (int now = divid-1; now < n; ++now) { if (divid == 1) { if (!now) tmax = mmax(0, ary[0]), dp[now] = ary[0]; else dp[now] = mmax(dp[now-1]+ary[now], ary[now]); } else { if (now == divid-1) tmax = dp[now-1]; nxt = mmax(tmax, dp[now]); dp[now] = mmax(tmax, dp[now-1])+ary[now]; tmax = nxt; } // printf("%cdp[%d] = %lld", "\n "[(bool)(now-divid+1)], now, dp[now]); } } ans = -INF; for (int i = m-1; i < n; ++i) ans = mmax(ans, dp[i]); printf("%lld\n", ans); } int main() { freopen("in.t", "r", stdin); freopen("out.t", "w", stdout); while( getin()) { judge(); } return 0; }
2017-09-06
相关文章推荐
- HDU 1024 Max Sum Plus Plus(dp多段最大子序列和)*
- hdu 1024 Max Sum Plus Plus (求一个序列中选出的m个不相交子段和的最大值)
- hdu 1024 Max Sum Plus Plus(K个最大连续子序列和)
- !HDU 1024 Max Sum Plus Plus-dp-(分组dp?最大分段子序列和)
- HDU 1024 Max Sum Plus Plus (最大和子序列增强版:求规定下标内的最大值)
- ☆HDU 1024 Max Sum Plus Plus 绝对能看懂得题解(难题,多个子段和的和最大)
- hdu 1024 Max Sum Plus Plus m段连续子序列最大和 dp
- hdu 1024 Max Sum Plus Plus(最大m子段和)
- [HDU 1024] Max Sum Plus Plus 多段子序列和
- hdu 1024 Max Sum Plus Plus(m段最大子列和)
- HDU - 1024 Max Sum Plus Plus (多段最大连续和+状态压缩)
- HDU 1024 Max Sum Plus Plus(最大M子段和)
- hdu 1024 Max Sum Plus Plus(dp求m个不相交子段和的最大值)
- Max Sum Plus Plus---hdu1024(动态规划求M段的最大和)
- HDU 1024 Max Sum Plus Plus最大m子段和
- HDU 1024 Max Sum Plus Plus【动态规划求最大M子段和详解 】
- 【m段最大连续子段和的和】HDU - 1024 Max Sum Plus Plus
- hdoj 1024 Max Sum Plus Plus(m个子段最大和)
- hdu 1024 Max Sum Plus Plus(动态规划+m子段和的最大值)
- HDU 1024 Max Sum Plus Plus求前n个数中的若干个数分为连续的m段的最大和值(解析)