这题目一直wa,原来是因为我把JUDGE写错了,对拍了一下午都没检查出来。水DP啊。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std; #define MAXN 1020
#define MAXM 35
#define INF 0xfffff int dp[MAXM][MAXN];
int l[MAXM];
int sums[MAXN]; int main() {
int n, m, sum;
int i, j, k, tmp; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d",&n)!=EOF && n) {
scanf("%d", &m);
for (i=; i<=m; ++i)
scanf("%d", &l[i]);
sums[] = ;
for (i=; i<=n; ++i) {
scanf("%d", &tmp);
sums[i] = sums[i-] + tmp;
}
sum = ;
memset(dp, , sizeof(dp));
for (i=m; i>; --i) {
sum += l[i];
for (j=n-sum+; j>; --j) {
dp[i][j] = max( dp[i][j+], dp[i+][j+l[i]]+(sums[j+l[i]-]-sums[j-]) );
}
}
printf("%d\n", dp[][]);
} return ;
}

【HDOJ】1244 Max Sum Plus Plus Plus的更多相关文章

  1. 【HDOJ】1003 Max Sum

    最开始使用递归DP解,stack overflow.化简了一些,复杂度为O(n)就过了. #include <stdio.h> int main() { int case_n, n; in ...

  2. 【leetcode】363. Max Sum of Rectangle No Larger Than K

    题目描述: Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the ma ...

  3. 【LeetCode】363. Max Sum of Rectangle No Larger Than K 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/max-sum- ...

  4. 【HDOJ】3473 Minimum Sum

    划分树解.主席树解MLE. /* 3473 */ #include <iostream> #include <sstream> #include <string> ...

  5. 【HDOJ】P2058 The sum problem

    题意很简单就是给你一个N和M,让你求在1-N的那些个子序列的值等于M 首先暴力法不解释,简单超时 再仔细想一想可以想到因为1-N是一个等差数列,可以运用我们曾经学过的只是来解决 假设开始的位置为s,结 ...

  6. 【LeetCode】813. Largest Sum of Averages 解题报告(Python)

    [LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  7. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  8. 【LeetCode】113. Path Sum II 解题报告(Python)

    [LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...

  9. 【LeetCode】#1 Two Sum

    [Question] Given an array of integers, return indices of the two numbers such that they add up to a ...

随机推荐

  1. 【动态页面】(二)Java反射

    Java的反射机制是Java语言非常重要的一个特性.先从Sun官网上看一下官网是怎样定义反射机制的. 大致翻译一下,翻译的可能不是非常准确. 反射(Reflection)是Java程序设计语言的一个特 ...

  2. hdu 4602 Partition (概率方法)

    Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. Linux TCP队列相关参数的总结

    作者:阿里技术保障锋寒 原文:https://yq.aliyun.com/articles/4252 摘要: 本文尝试总结TCP队列缓冲相关的内核参数,从协议栈的角度梳理它们,希望可以更容易的理解和记 ...

  4. 转载:C#中委托、事件与Observer设计模式

    原文地址 http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx 感谢博主分享! 范例说明 假设 ...

  5. C#反射—解决类的实例化问题

    利用简单工厂模式来改进抽象工厂使用的复杂性(抽象工厂详见 设计模式之—抽象工厂模式) 数据表(User)业务处理接口(IUser) namespace FactoryMethodPatternDB.C ...

  6. C# WebService 基础实例

    1.整个Demo结构:如下图: 2.新建项目--选择asp.net web服务应用程序TestWebService 3.重新命名Service1.asmx为MyService.asmx 4.右键MyS ...

  7. ASP.NET的WebConfig

    转:http://blog.csdn.net/q3498233/article/details/8137364 WebConfig 花了点时间整理了一下ASP.NET Web.config配置文件的基 ...

  8. Android onConfigurationChanged(Configuration cfg) 无法触发问题

     1.android:configChanges="orientation|keyboardHidden"的使用  当在activity加上android:configChange ...

  9. amCharts 破解

    官网下载 http://www.amcharts.com 然后找到amcharts.js , 打开搜索关键字 “utm_source=swf&utm_medium=demo&utm_c ...

  10. bitmap index

    bitmap index 说明: set echo on drop table t purge; create table t ( processed_flag ) ); create bitmap ...