【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 ...
随机推荐
- Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
1. Collection集合的基本功能测试: package cn.itcast_01; import java.util.ArrayList; import java.util.Collectio ...
- mcrypt.h not found. Please reinstall libmcrypt
在centos上对php5.6进行源码安装的时候, 出现了如题所示错误提示, 原因是由于centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包 解决办法使用php ...
- 模板-->Guass消元法(求解多元一次方程组)
如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 简单的测试 None 代码模板 /* * TIME COMPLEXITY:O(n^3) * PARAMS: * a The ...
- SPOJ 4053 - Card Sorting 最长不下降子序列
我们的男主现在手中有n*c张牌,其中有c(<=4)种颜色,每种颜色有n(<=100)张,现在他要排序,首先把相同的颜色的牌放在一起,颜色相同的按照序号从小到大排序.现在他想要让牌的移动次数 ...
- 9.7noip模拟试题
题目名称 日历游戏 最大公约数 密码 英文代号 calendar gcd pasuwado 输入文件名 calendar.in gcd.in pasuwado.in 输出文件名 calendar.ou ...
- Linq 实现普通sql中 where in 的功能
user.ProjectIds 的值是使用逗号分隔的 例如:1,2,3 projectList = (from a in projectList where (user.ProjectIds.Spli ...
- windows下安装CI框架
CI框架是一个非常流行的 mvc框架, CI框架如何安装和使用,在CI中文网已经讲的比较详细了 ,这里记录下几个需要注意的地方. 一. index.php问题 把压缩包下载解压到项目根目录即可运行里面 ...
- 在SpringMVC框架下建立Web项目时web.xml到底该写些什么呢?
刚刚初学Spring MVC,却连一个简单的helloworld都搞的懵懵懂懂的,配置文件搞不清,各种文件之间的逻辑关系也不懂,连续看了好些日子的Spring MVC了,今天终于下定决心,每天记录一点 ...
- 多重部分和的计数dp
题目大意:有k个大小不同的数字ai,每种各有bi个,求从这些数中选出和为n的排列数 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=1 ...
- C++ Primer 5th 第10章 泛型算法
练习10.1:头文件algorithm中定义了一个名为count的函数,它类似find,接受一对迭代器和一个值作为参数.count返回给定值在序列中出现的次数.编写程序,读取int序列存入vector ...