题目链接:Pictures with Kittens (easy version)

题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和。

题解:$dp[i][j]$:以i为结尾选择j个数字的最大和。

$dp[i][j]=max(dp[i][j],dp[s][j-1]+a[i])$,$s为区间[i-k,i)$。

以i为结尾的最大和可以由i之前k个位置中的其中一个位置选择j-1个,再加上当前位置的ai得到。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
const int N=+;
ll a[N],dp[N][N],ans=-1e18; int main(){
int n,k,x;
scanf("%d%d%d",&n,&k,&x);
for(int i=;i<=n;i++) scanf("%lld",&a[i]); for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
dp[i][j]=-1e18; dp[][]=; for(int j=;j<=x;j++){
for(int i=;i<=n;i++){
for(int s=max(,i-k);s<i;s++){
dp[i][j]=max(dp[i][j],dp[s][j-]+a[i]);
}
}
} for(int i=n-k+;i<=n;i++) ans=max(ans,dp[i][x]);
if(ans<) ans=-; printf("%lld\n",ans);
return ;
}

Codeforces 1077F1 Pictures with Kittens (easy version)(DP)的更多相关文章

  1. Codeforces 1077F2 Pictures with Kittens (hard version)(DP+单调队列优化)

    题目链接:Pictures with Kittens (hard version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:数据量5000, ...

  2. Codeforces 1542E2 - Abnormal Permutation Pairs (hard version)(DP)

    upd on 2021.7.7:修了个 typo Codeforces 题目传送门 & 洛谷题目传送门 首先考虑怎样处理"字典序小"这个问题,按照字典序比大小的套路,我们可 ...

  3. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  4. Ping-Pong (Easy Version)(DFS)

    B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. E1. String Coloring (easy version)(贪心)

    E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...

  6. Codeforces Round #260 (Div. 2)C. Boredom(dp)

    C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  7. Codeforces Global Round 7 D1. Prefix-Suffix Palindrome (Easy version)(字符串)

    题意: 取一字符串不相交的前缀和后缀(可为空)构成最长回文串. 思路: 先从两边取对称的前后缀,之后再取余下字符串较长的回文前缀或后缀. #include <bits/stdc++.h> ...

  8. E1. Array and Segments (Easy version)(暴力) && E2. Array and Segments (Hard version)(线段树维护)

    题目链接: E1:http://codeforces.com/contest/1108/problem/E1 E2:http://codeforces.com/contest/1108/problem ...

  9. CodeForces - 1183H Subsequences (hard version) (DP)

    题目:https://vjudge.net/contest/325352#problem/C 题意:输入n,m,给你一个长度为n的串,然后你有一个集合,集合里面都是你的子序列,集合里面不能重复,集合中 ...

随机推荐

  1. 【原】Java学习笔记003 - 数据类型

    package cn.temptation; public class Sample01 { public static void main(String[] args) { System.out.p ...

  2. hrbust1140 数字和问题

    题目: 定义一种操作为:已知一个数字,对其各位数字反复求和,直到剩下的数是一位数不能求和为止.例如:数字2345,第一次求和得到2 + 3 + 4 + 5 = 14,再对14的各位数字求和得到1 + ...

  3. 持续代码质量管理-SonarQube-7.3简单使用

    安装了SonarQube以及Sonar Scanner之后,就需要那代码检测了.当然为了方便我们使用已有现成的demo,知道到对应的git地址下载即可. 1. sonar-examples下载 htt ...

  4. 阿里Canal安装和代码示例

    Canal的简单使用 canal可以用来监控数据库数据的变化,从而获得新增数据,或者修改的数据,用于实际工作中,比较实用,特此记录一下 Canal简介 canal是应阿里巴巴存在杭州和美国的双机房部署 ...

  5. Java的动态代理

    什么是动态代理(dynamic proxy) 动态代理(以下称代理),利用Java的反射技术(Java Reflection),在运行时创建一个实现某些给定接口的新类(也称“动态代理类”)及其实例(对 ...

  6. Linux:Day12(下) 进程、任务计划

    vmstat命令: vmstat [options] [delay [ count]] procs: r:等待运行的进程的个数: b:处于不可中断睡眠态的进程个数:(被阻塞的队列的长度): memor ...

  7. Bubble Babble Binary Data Encoding的简介以及bubblepy的安装使用方法

    Bubble Babble Binary Data Encoding是由Antti Huima创建的一种编码方法,可以把二进制信息表示为由交替的元音和辅音组成的伪词(pseudo-words),主要用 ...

  8. 看完python这段爬虫代码,java流泪了c#沉默了

    哈哈,其实很简单,寥寥几行代码网页爬一部小说,不卖关子,立刻开始. 首先安装所需的包,requests,BeautifulSoup4 控制台执行 pip install requests pip in ...

  9. Mysql_安装

    安装环境:win7 1.下载zip安装包: MySQL8.0 For Windows zip包下载地址:https://dev.mysql.com/downloads/file/?id=476233, ...

  10. OCR技术浅析-tesserOCR(3)

    tesserOCR使用 tesserOCR是文字识别软件(惠普公司开源) Optical Character Recognition (OCR)即光学字符辨识是把打印文本转换成一个数字表示的过程.它有 ...