hdu3905 Sleeping (区间dp)
listen to the teacher. Today, he hears that the teacher will have a revision class. The class is N (1 <= N <= 1000) minutes long. If ZZZ listens to the teacher in the i-th minute, he can get Ai points (1<=Ai<=1000). If he starts listening, he will listen to
the teacher at least L (1 <= L <= N) minutes consecutively. It`s the most important that he must have at least M (1 <= M <= N) minutes for sleeping (the M minutes needn`t be consecutive). Suppose ZZZ knows the points he can get in every minute. Now help ZZZ
to compute the maximal points he can get.
1 2 3 4 5 6 7 8 9 10
)。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define maxn 1005
#define inf 999999999
int v[maxn],sum[maxn];
int dp[maxn][maxn],dp_tmp[maxn][maxn];
int main()
{
int n,m,l,i,j,k;
while(scanf("%d%d%d",&n,&m,&l)!=EOF)
{
sum[0]=0;
for(i=1;i<=n;i++){
scanf("%d",&v[i]);
sum[i]=sum[i-1]+v[i];
}
for(i=0;i<=n;i++){
for(j=0;j<=m && j<=i;j++){
dp[i][j]=0;
dp_tmp[i][j]=0;
}
}
for(i=0;i<=n;i++){
if(i>=l)dp[i][0]=sum[i];
dp[i][i]=0;
}
for(i=1;i<=n;i++){
for(j=1;j<=i && j<=m;j++){
dp[i][j]=max(dp[i][j],dp[i-1][j-1] ); //第i分钟睡
if(i-l>=j){
dp[i][j]=max(dp[i][j],dp_tmp[i-l][j]+sum[i]-sum[i-l] );
}
if(i-l>=j) //这里是为算i+1做铺垫,算出dp_tmp[i+1-l][j]
dp_tmp[i+1-l][j]=max(dp[i+1-l][j],dp_tmp[i-l][j]+v[i+1-l] );
}
}
printf("%d\n",dp[n][m]);
}
return 0;
}
hdu3905 Sleeping (区间dp)的更多相关文章
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- BZOJ 1260&UVa 4394 区间DP
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...
- 区间dp总结篇
前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...
- Uva 10891 经典博弈区间DP
经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能 ...
随机推荐
- (二)数据源处理3-python处理包含合并单元格的excel
分析:
- python3 最基本且简单的实现组合设计模式
组合模式是把一个类别归为一个整体,并且组织多个整体之间的关系,使用通过树形结构来描述所有整体. 一般的编写方式为一个类别对象下添加多个该对象的元素,该对象又为其它对象下的元素.简单来说就是一个学校有一 ...
- 大文件上传FTP
需求 将本地大文件通过浏览器上传到FTP服务器. 原有方法 将本地文件整个上传到浏览器,然后发送到node服务器,最后由node发送到FTP服务器. 存在问题 浏览器缓存有限且上传速率受网速影响,当文 ...
- fileinput模块用法
fileinput模块功能: 提供拼接一个或多个文本文件的功能,可以通过使用for循环来读取一个或多个文本文件的所有行,从而进行逐行处理(如进行显示.替换.添加行号等). 其功能类似于linux命令的 ...
- 屏蔽每分钟SSH尝试登录超过10次的IP
屏蔽每分钟SSH尝试登录超过10次的IP 方法1:通过lastb获取登录状态: #!/bin/bash DATE=$(date +"%a %b %e %H:%M") #星期月天时分 ...
- centos7安装vsftpd最大的坑
1.检查用户和密码没有错误2.vsftpd.conf配置没有错误3.检查/etc/vsftpd/vsftpd.conf 里面pam_service_name =vsftpd4.终极boss查看vim ...
- Docker 如何动态给SpringBoot项目传参
关于SpringBoot配置数据源 在项目开发中,我们往往需要配置多套不同的配置环境例如:本地开发.测试环境.部署环境.每一个环境的数据源配置可能都不同,因此需要写不同的数据源配置.如果用Docker ...
- Python 身份证校验代码
Python 身份证校验代码 居民身份证bai编号识别 1.身份证编码规则如下:根据[中华人民共和国国家标准GB11643-1999]中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本 ...
- pytorch——不用包模拟简单线性预测,数据类型,创建tensor,索引与切片
常见的学习种类 线性回归,最简单的y=wx+b型的,就像是调节音量大小.逻辑回归,是否问题.分类问题,是猫是狗是猪 最简单的线性回归y=wx+b 目的:给定大量的(x,y)坐标点,通过机器学习来找出最 ...
- .NET Core部署到linux(CentOS)最全解决方案,入魔篇(使用Docker+Jenkins实现持续集成、自动化部署)
通过前面三篇: .NET Core部署到linux(CentOS)最全解决方案,常规篇 .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx) .N ...