codeforces 1077F1
题目:https://codeforces.com/contest/1077/problem/F1
题意:
你有n幅画,第i幅画的好看程度为ai,再给你两个数字k,x 表示你要从中选出刚好x幅画,并且相邻选的两幅画之间没选画的个数不能≥k,求好看程度之和最大能多少
题解:
我选了第i 副画,那么我接下来的k副画是都可以选的,定义状态为,前i副画我选了j个,第i副画为必须选的画
然后扫一遍必须选x副画后可以得到的最大值是多少
转移方程:
dp[i][j]=max(dp[i][j-1]+a[i],dp[i][j]);
代码如下:
#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
const int INF=0x3f3f3f3f;
typedef long long ll;
ll dp[maxn][maxn];
int a[maxn];
int main(){
int n,k,x;
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=i-;j>=max(i-k,);j--){
for(int m=;m<=x;m++){
//第i个选了j个后第i个必须选的值是多少
dp[i][m]=max(dp[j][m-]+a[i],dp[i][m]);
}
}
}
ll ans=-;
//第x个必须选的最大值即是答案
for(int i=n;i>n-k;i--){
if(dp[i][x]) ans=max(ans,dp[i][x]);
}
cout<<ans<<endl;
}
codeforces 1077F1的更多相关文章
- Codeforces 1077F1 Pictures with Kittens (easy version)(DP)
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- narcissus
public class narcissus { public static void main(String args[]) { long u=0,t=0,h=0,y=0,k=0; for(long ...
- Spark Streaming实时处理应用
1 框架一览 事件处理的架构图如下所示. 2 优化总结 当我们第一次部署整个方案时,kafka和flume组件都执行得非常好,但是spark streaming应用需要花费4-8分钟来处理单个 ...
- 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(二):Apache安装和配置
基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...
- 初步学习pg_control文件之十二
接前问,初步学习pg_control文件之十一,再来看下面这个 XLogRecPtr minRecoveryPoint; 看其注释: * minRecoveryPoint is updated to ...
- 4269: 再见Xor
4269: 再见Xor 链接 分析: 和SGU 275唯一不同的就是需要求出次小值,那么异或出最大值的所有元素中,找到最小的,去除即可. 代码: #include<bits/stdc++.h&g ...
- 字符串分割(C++)
一.用strtok函数进行字符串分割 原型: char *strtok(char *str, const char *delim); 功能:分解字符串为一组字符串. 参数说明:str为要分解的字符串, ...
- How to enable download EXE files from the Sharepoint website
As we all know,many applications have forbidden to upload and download exe files.Because the e ...
- jmeter插件下载
https://jmeter-plugins.org/wiki/Start/ 插件下载好后,将插件lib目录下的jar包放在jmeter安装目录下的lib里,插件ext目录下的jar包放在jmeter ...
- JS 客户端检测
能力检测 能力检测的目标不是识别特定的浏览器,而是识别浏览器的能力. 能力检测需要注意两点: 先检测达成目的的最常用的特性.因为先检测最常用的特性可以保证代码最优化,因为在多数情况下都可以避免测试多个 ...
- tomcat 异常
Removing obsolete files from server... Could not clean server of obsolete files: null java.lang.Null ...