codeforces467C
2024-08-29 16:12:33
George and Job
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers:
[l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 < l2 ≤ r2 < ... < lk ≤ rk ≤ n; ri - li + 1 = m),
in such a way that the value of sum is maximal possible. Help George to cope with the task.
Input
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
Output
Print an integer in a single line — the maximum possible value of sum.
Examples
Input
5 2 1
1 2 3 4 5
Output
9
Input
7 1 3
2 10 7 18 5 33 0
Output
61 sol:题意比较gou,用 K 条长度为 m 的不相交线段覆盖一段长度为 n 的数列,使得覆盖到的和最大
XJBdp应该不难,n2dp即可完美AC此题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,K;
ll Cost[N],Qzh[N];
ll dp[N][N];
int main()
{
int i,j;
R(n); R(m); R(K);
for(i=;i<=n;i++) R(Cost[i]);
for(i=;i<=n;i++) Qzh[i]=Qzh[i-]+Cost[i];
dp[][]=;
for(j=;j<=K;j++)
{
for(i=j*m;i<=n;i++)
{
dp[i][j]=max(dp[i-][j],dp[i-m][j-]+Qzh[i]-Qzh[i-m]);
}
}
Wl(dp[n][K]);
return ;
}
/*
Input
5 2 1
1 2 3 4 5
Output
9 Input
7 1 3
2 10 7 18 5 33 0
Output
61
*/
最新文章
- 一个简易的MysQL性能查询脚本
- get与post需要注意的几点
- .NET中的CTS、CLS和CLR
- HBase之计数器
- 从C#到Objective-C
- LeetCode——Path Sum II
- Mac OS X 安装后的简单设置
- 实验:企业级分布式存储应用与实战-mogilefs实现
- ajax异步的问题,(主要解决有时候前台打断点和不打断点结果不一样的问题,一般情况下是存在异步的问题)
- javaweb面试题
- 使用Eclipse来操作HDFS的文件
- Media Queries 媒体查询常见设备断点
- python - wmi模块学习(windwos硬件信息获取)
- c++字符串前几位,后几位的截取
- POJ - 2240 Arbitrage(Bellman-Ford)
- 世纪互联提供的关于Powershell中将虚拟机加入备份保管库的方法
- prometheus-dashboard-to-grafana
- Swift - 3.0 去掉 C 风格循环
- NERDTree基本使用教程
- 【BZOJ】1044: [HAOI2008]木棍分割(二分+dp)