F1. Pictures with Kittens (easy version)

题目链接:https://codeforces.com/contest/1077/problem/F1

题意:

给出n个数,以及k,x,k即长度为k的区间至少选一个,x的意思是一共要选x个,少一个或者多一个都不行。

选一个会得到一定的奖励,问在满足条件的前提下,最多得到多少的奖励。

题解:

简单版本数据量比较小,考虑比较暴力的动态规划。

dp[i,j]表示前i个数,要选第i个数,目前选了j个所得到的最大奖励,那么当前就可以从[i-k,i-1]转移过来,因为必须保证长度为k的区间至少要选一个。

直接给出代码吧:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = ;
int k,n,x;
int a[N];
ll dp[N][N];
int main(){
scanf("%d%d%d",&n,&k,&x);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
memset(dp,-INF,sizeof(dp));
dp[][]=;
for(int i=;i<=n;i++){
for(int j=;j<=min(i,x);j++){
for(int p=max(,i-k);p<=i-;p++){
dp[i][j]=max(dp[i][j],dp[p][j-]+a[i]);
}
}
}
ll ans = -INF;
for(int i=n;i>max(,n-k);i--) ans=max(ans,dp[i][x]);
if(ans<) cout<<-;
else cout<<ans;
return ;
}

Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)的更多相关文章

  1. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  2. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  3. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  4. Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)

    D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...

  5. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  6. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  7. Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)

    https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...

  8. Codeforces Round #521 (Div. 3)

    B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过.  D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...

  9. Codeforces Round #521 Div. 3 玩耍记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

随机推荐

  1. ruby 可枚举模块Enumerable

    Enumerable模块提供了遍历,搜索,比较,排序等方法.如果我们自定义的类需要实现这些方法,必须实现一个each方法.如果需要使用max,min,sort等方法,因为这些方法是集合的元素之间的排序 ...

  2. 675. Cut Off Trees for Golf Event

    // Potential improvements: // 1. we can use vector<int> { h, x, y } to replace Element, sortin ...

  3. 复位自动ID的问题有兩種方法

    复位自动ID的问题 有兩種方法:      方法1:      truncate   table   你的表名   --這樣不但將數據刪除,而且可以重新置位identity屬性的字段.         ...

  4. HyperLedger Fabric 1.4 超级账本起源(5.1)

    至比特币开源以来,无数技术人员对其进行研究,并且对该系统经过了无数次改进,超级账本项目(Hyperledger)最初也是用来改善比特币的底层技术,最终由Linux基金会组织发展起来.       开放 ...

  5. HBase 是什么

    Apache HBase™ is the Hadoop database, a distributed, scalable, big data store. HBase 是 Hadoop databa ...

  6. Linq中dbSet 的查询

    1.Find:按照关键字的ID号来查询(速度快) 如: ADShiTi aDShiTi = db.ADShiTis.Find(id); 2.FirstOrDefault:根据部分条件查询,显示最前的一 ...

  7. 第四模块:网络编程进阶&数据库开发 考核实战

     1.什么是进程?什么是线程? 什么是协程? 进程:正在进行的一个过程或者说一个任务.而负责执行任务则是cpu. 线程:在传统操作系统中,每个进程有一个地址空间,而且默认就有一个控制线程 协程是一种用 ...

  8. LeetCode:17. Letter Combinations of a Phone Number(Medium)

    1. 原题链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ 2. 题目要求 给定一 ...

  9. itop-4412开发板使用第一篇-信号量的学习使用

    1. 本次基于itop-4412研究下Linux信号量的使用方法. 2. 创建信号量的函数,信号量的头文件在那个路径?编译应用程序的话,头文件有3个路径,内核源码头文件,交叉编译器头文件,ubuntu ...

  10. This content database has a schema version which is not supported in this farm.

          I want to move the website to another server. The new server has reinstall Sharepoint2013 serv ...