【HDOJ】1244 Max Sum Plus Plus Plus
这题目一直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的更多相关文章
- 【HDOJ】1003 Max Sum
最开始使用递归DP解,stack overflow.化简了一些,复杂度为O(n)就过了. #include <stdio.h> int main() { int case_n, n; in ...
- 【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 ...
- 【LeetCode】363. Max Sum of Rectangle No Larger Than K 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/max-sum- ...
- 【HDOJ】3473 Minimum Sum
划分树解.主席树解MLE. /* 3473 */ #include <iostream> #include <sstream> #include <string> ...
- 【HDOJ】P2058 The sum problem
题意很简单就是给你一个N和M,让你求在1-N的那些个子序列的值等于M 首先暴力法不解释,简单超时 再仔细想一想可以想到因为1-N是一个等差数列,可以运用我们曾经学过的只是来解决 假设开始的位置为s,结 ...
- 【LeetCode】813. Largest Sum of Averages 解题报告(Python)
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- 【LeetCode】113. Path Sum II 解题报告(Python)
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...
- 【LeetCode】#1 Two Sum
[Question] Given an array of integers, return indices of the two numbers such that they add up to a ...
随机推荐
- 适配iOS7uinavigationbar遮挡tableView的问题
//适配iOS7uinavigationbar遮挡tableView的问题 if([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0 ...
- poj 3735 大数量反复操作问题(矩阵高速幂)
题意:一个一维数组,3种操作: a: 第i个数+1,b: 第i个数=0 ,c::交换某俩处的数. 由三种基本操作构成一组序列,反复该序列m次(m<10^9),问结果 属于一种综合操作反复型: ...
- configure JAAS for jboss 7.1 and mysql--reference
Hello all, In this tutorial we are going to configure JAAS for jboss 7.1 and mysql for Form based au ...
- Creating a Navigation Drawer 创建一个导航侧边栏
The navigation drawer is a panel that displays the app’s main navigation options on the left edge of ...
- Struts1 中实现Action跳转地址栏变化的方法
Action进行跳转,有时候地址栏不变化,如果重复刷新就会重复提交, 这里一般需要进行重定向: 1.在xml里面进行配置 <action path="/checkCdconfirmEn ...
- android-'Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 8'
解决的方案是将jdk1.7制定的版本定制为jdk.6.即 在eclipse中,右键项目->Properties->Java Compiler->enable "projec ...
- 对exp full 和 imp full的认识
前段时间听同事说.Toad 工具可以打开 oracle数据库的 .dmp 文件.今天抽空试了试,果然可以!Oracle 执行 export 操作 会把 表的定义导出.表的数据导出. 其实 .dmp 文 ...
- 使用Spring MVC,Mybatis框架等创建Java Web项目时各种前期准备的配置文件内容
1.pom.xml 首先,pom.xml文件,里面包含各种maven的依赖,代码如下: <project xmlns="http://maven.apache.org/POM/4.0. ...
- 嵌入式开发(一) Ubuntu12.04下搭建交叉编译环境
操作系统:Ubuntu12.04 AMD64位 交叉编译环境:arm-Linux gcc版本4.4.3 前言: 首先理解一下交叉编译的意思.我们要给嵌入式设备写应用程序,但是又不能在嵌入式设备上完成所 ...
- 最短路径算法——Dijkstra,Bellman-Ford,Floyd-Warshall,Johnson
根据DSqiu的blog整理出来 :http://dsqiu.iteye.com/blog/1689163 PS:模板是自己写的,如有错误欢迎指出~ 本文内容框架: §1 Dijkstra算法 §2 ...