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的区间至少要选一个。

直接给出代码吧:

  1. #include <bits/stdc++.h>
  2. #define INF 0x3f3f3f3f
  3. using namespace std;
  4. typedef long long ll;
  5. const int N = ;
  6. int k,n,x;
  7. int a[N];
  8. ll dp[N][N];
  9. int main(){
  10. scanf("%d%d%d",&n,&k,&x);
  11. for(int i=;i<=n;i++) scanf("%d",&a[i]);
  12. memset(dp,-INF,sizeof(dp));
  13. dp[][]=;
  14. for(int i=;i<=n;i++){
  15. for(int j=;j<=min(i,x);j++){
  16. for(int p=max(,i-k);p<=i-;p++){
  17. dp[i][j]=max(dp[i][j],dp[p][j-]+a[i]);
  18. }
  19. }
  20. }
  21. ll ans = -INF;
  22. for(int i=n;i>max(,n-k);i--) ans=max(ans,dp[i][x]);
  23. if(ans<) cout<<-;
  24. else cout<<ans;
  25. return ;
  26. }

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. Python学习笔记:第2天while循环 运算符 格式化输出 编码

    目录 1. while循环 continue.break和else语句 2. 格式化输出 3. 运算符 3.1 算数运算 3.2 比较运算符 3.3 赋值运算符 3.4 逻辑运算符 3.5 成员运算符 ...

  2. Qt之pro文件解析

    在我们创建Qt工程项目时,Qt Creator总会创建一个.pro文件,我们称.pro文件为Qt的工程管理文件.一个工程项目可以包含一个或多个.pro文件.理解和掌握pro文件的用法,将有利于Qt开发 ...

  3. 521. [NOIP2010] 引水入城 cogs

    521. [NOIP2010] 引水入城 ★★★   输入文件:flow.in   输出文件:flow.out   简单对比时间限制:1 s   内存限制:128 MB 在一个遥远的国度,一侧是风景秀 ...

  4. Hibernate-ORM:01.Hibernate恍如隔世般初见

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 对于学过ORM框架的朋友来说,上手HibernateORM来说,既熟悉有有一点陌生,熟悉无非是灵魂相通,陌生的 ...

  5. 「暑期训练」「Brute Force」 Optimal Point on a Line (Educational Codeforces Round 16, B)

    题意 You are given n points on a line with their coordinates $x_i$. Find the point x so the sum of dis ...

  6. zabbix 一些问题随记

    1. zabbix运行不了,显示被锁,去检查日志中的报错 2. 配置界面,连接不到数据库,检查server配置文件,mysql授权命令要准确,重启 3. 显示没有php文件,下载即可,或者修改网页访问 ...

  7. SDOI2013森林

    题面 主席树启发式合并,每次连边维护并查集,集合大小,求lca所需信息,合并两个树上的主席树, 重点看代码. #include <iostream> #include <algori ...

  8. 剑指offer-数值的整数次方12

    class Solution: def Power(self, base, exponent): # write code here if base==0: return 0 if exponent= ...

  9. kinit

    su tf$ kinit -k -t /tmp/tf.keytab tf/admin@SINO.COM

  10. Daily Scrum02 12.01

    今天是2013年12月的第一天,希望大家都有一个新的开始,一起努力!     Member Today's Task Tomorrow's Task 李孟 Task 856: 熟悉单元测试方法熟悉单元 ...