CF1197D Yet Another Subarray Problem
思路:
使用动态规划,在经典的最大子段和解法基础上进行扩展。dp[i][j]表示以第i个数为结尾,并且长度模m等于j的所有子段的最大cost。
实现:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = ;
ll a[N], dp[N][];
int main()
{
int n; ll m, k;
while (cin >> n >> m >> k)
{
memset(dp, , sizeof dp);
for (int i = ; i <= n; i++) cin >> a[i];
ll res = ;
dp[][] = -k;
for (int i = ; i < m; i++) dp[][i] = -INF;
for (int i = ; i <= n; i++)
{
for (int j = ; j < m; j++)
{
if (j == (m == ? : ))
{
dp[i][j] = max(dp[i - ][] + a[i] - k, a[i] - k);
}
else
{
dp[i][j] = max(dp[i - ][(j - + m) % m] + a[i], a[i] - k);
}
res = max(res, dp[i][j]);
}
}
cout << res << endl;
}
return ;
}
CF1197D Yet Another Subarray Problem的更多相关文章
- maximum subarray problem
In computer science, the maximum subarray problem is the task of finding the contiguous subarray wit ...
- 动态规划法(八)最大子数组问题(maximum subarray problem)
问题简介 本文将介绍计算机算法中的经典问题--最大子数组问题(maximum subarray problem).所谓的最大子数组问题,指的是:给定一个数组A,寻找A的和最大的非空连续子数组.比如 ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...
- Educational Codeforces Round 69 D. Yet Another Subarray Problem
Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 题目链接 题意: 求\(\sum_ ...
- D. Yet Another Subarray Problem 思维 难 dp更好理解
D. Yet Another Subarray Problem 这个题目很难,我比赛没有想出来,赛后又看了很久别人的代码才理解. 这个题目他们差不多是用一个滑动窗口同时枚举左端点和右端点,具体如下: ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 【数学+分块】
一.题目 D. Yet Another Subarray Problem 二.分析 公式的推导时参考的洛谷聚聚们的推导 重点是公式的推导,推导出公式后,分块是很容易想的.但是很容易写炸. 1 有些地方 ...
- CodeForces 1197D Yet Another Subarray Problem
Time limit 2000 ms Memory limit 262144 kB Source Educational Codeforces Round 69 (Rated for Div. 2) ...
- CodeForces 1197 D Yet Another Subarray Problem
题面 不得不说CF还是很擅长出这种让人第一眼看摸不着头脑然后再想想就发现是个SB题的题的hhh(请自行断句). 设sum[]为前缀和数组,那么区间 [l,r]的价值为 sum[r] - sum[l-1 ...
- (转)Maximum subarray problem--Kadane’s Algorithm
转自:http://kartikkukreja.wordpress.com/2013/06/17/kadanes-algorithm/ 本来打算自己写的,后来看到上述链接的博客已经说得很清楚了,就不重 ...
随机推荐
- CF1185F Two Pizzas 状压
你发现 pizza 种类数不会很多,状压一下就可以了 code: #include <bits/stdc++.h> #define M 11 #define N 100005 #defin ...
- 垂直对齐vertical-align
<body> <img src="显示和隐藏/tu.png" alt=""> 图片和文字是默认基线(baseline)对齐,这样会导致图 ...
- while循环实现十进制转二进制
#include <stdio.h> int main(void){ int a,n; printf("pls input number:\n"); scanf(&qu ...
- ORA-01033:ORACLE initialization or shutdown
ora-01033 错误处理:DOS下依次执行以下命令sqlplus/nologconnect sys/密码@orcl as sysdbashutdown normalstartup mountSQL ...
- 坑:找到LoadRunner中Recording Options和 Run Time Settings配置选项确实的原因
在loadrunner安装好后,打开页面查看发现分别的缺失内容如下: 现象: 1. Recording Options 2.Run Time Settings 3.解决 原因是LR是付费的,你的安装包 ...
- 用avalon框架怎么做轮播图?
avalon这个框架其实特别的小众,做个轮播图呢?在github上的例子只有一个,而且功能特别的少,有的引入的插件与avalon里面的指令又不兼容,所以找了一个owl-carousel,目前实现了移动 ...
- docker理论 Cgroup namespace 各种隔离
耦合 是指两个或两个以上的体系或者两种运动形式间通过相互作用而批次影响以至联合起来的现象. Nginx与apache 在同一台服务器运行都占用80端口,起冲突这是我们修改其中一个端口为8080 半解耦 ...
- apache不能解析php之解决办法
记录一下Ubuntu16.04下的apache服务器不能解析php的问题,如图所示: 对于这个Ubuntu16.04最直接最快速的解决办法就是执行如下命令: sudo apt-get install ...
- Ibatis自动解决sql注入机制
疑问1:为什么IBatis解决了大部分的sql注入?(实际上还有部分sql语句需要关心sql注入,比如like) 之前写Java web,一直使用IBatis,从来没有考虑过sql注入:最近写php( ...
- 第10组 Alpha冲刺(3/6)
链接部分 队名:女生都队 组长博客: 博客链接 作业博客:博客链接 小组内容 恩泽(组长) 过去两天完成了哪些任务 描述 对推送模块进行详细划分 基于用户的协同过滤,寻找更感兴趣的话题 学习API文档 ...