Codeforces Round #243 (Div. 1)A. Sereja and Swaps 暴力
1 second
256 megabytes
standard input
standard output
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:
A swap operation is the following sequence of actions:
- choose two indexes i, j (i ≠ j);
- perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.
What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?
The first line contains two integers n and k (1 ≤ n ≤ 200; 1 ≤ k ≤ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 ≤ a[i] ≤ 1000).
In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.
10 2
10 -1 2 2 2 2 2 2 -1 10
32
5 10
-1 -1 -1 -1 -1
-1 题意:给你一串数列,允许换K次位置,然后让你求一个最大的连续和
题解:暴力枚举区间就是!
int a[maxn];
vector<int>kiss;
vector<int>miss;
int main()
{
int n,m,ans,i,j,k;
while(cin>>n>>m)
{
for(i=;i<=n;i++)
scanf("%d",&a[i]);
ans=-inf;
for(i=;i<=n;i++)
{
int sum=;
for(j=i;j<=n;j++)
{
kiss.clear();
miss.clear();
sum=;
for(k=i;k<=j;k++)
{
kiss.push_back(a[k]);
sum+=a[k];
}
for(k=;k<=n;k++)
{
if(k<i||k>j)
miss.push_back(a[k]);
}
sort(kiss.begin(),kiss.end());
sort(miss.begin(),miss.end());
ans=max(ans,sum);
for(k=;k<=m&&k<=kiss.size()&&k<=miss.size();k++)
{
sum-=kiss[k-];
sum+=miss[miss.size()-k];
ans=max(ans,sum);
}
}
}
cout<<ans<<endl;
}
return ;
}
Codeforces Round #243 (Div. 1)A. Sereja and Swaps 暴力的更多相关文章
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)
题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #243 (Div. 2) A. Sereja and Mugs
#include <iostream> #include <vector> #include <algorithm> #include <numeric> ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #243 (Div. 2) A~C
题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
- Codeforces Round #243 (Div. 2)——Sereja and Table
看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...
随机推荐
- 十五、springboot集成定时任务(Scheduling Tasks)(二)之(线程配置)
配置类: /** * 定时任务线程配置 * */ @Configuration public class SchedulerConfig implements SchedulingConfigurer ...
- keras LSTM中间的dropout
TM有三个 model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2)) 第一个dropout是x和hidden之间的dropout,第二个是hid ...
- java基础22 日期类、日历类、日期格式类
package com.dhb.code; import java.text.ParseException; import java.text.SimpleDateFormat; import jav ...
- Java容器---Set: HashSet & TreeSet & LinkedHashSet
1.Set接口概述 Set 不保存重复的元素(如何判断元素相同呢?).如果你试图将相同对象的多个实例添加到Set中,那么它就会阻止这种重复现象. Set中最常被使用的是测试归属性,你可以 ...
- Kafka ACL使用实战(单机版)
一.简介 自0.9.0.0.版本引入Security之后,Kafka一直在完善security的功能.当前Kafka security主要包含3大功能:认证(authentication).信道加密( ...
- Effective STL 学习笔记 Item 16:vector, string & C API
有时需要支持 C 的接口,但这并不复杂. 对于 vector 来讲, \(v[0]\) 的地址 \(\&v[0]\) 即可作为数组指针传递给 C API: 1: // Legacy C API ...
- Android仿苹果版QQ下拉刷新实现(一) ——打造简单平滑的通用下拉刷新控件
前言: 忙完了结婚乐APP的开发,终于可以花一定的时间放在博客上了.好了,废话不多说,今天我们要带来的效果是苹果版本的QQ下拉刷新.首先看一下目标效果以及demo效果: 因为此效果实现的步骤 ...
- OneNote无法同时设置中英文字体设置解决办法
如果你是一位OneNote老用户,无论是2003.2007还是2010或者最新的2013版本,都一直存在一个Bug,就是无法同时设置中英文字体(比如在Word中就可以分别设置不同的).我搜了一下,在微 ...
- 如何查看K8S的网络是否完好
今天工作中遇到这个问题, 检查从以下几个方面入手. 一,查看各个POD的LOG,如果有错误,则要解决了再继续 二,登陆各个POD之间,互相要能PING通. 三,在物理节点上可以PING通SERVICE ...
- C++中memcpy和memmove
二者都是内存拷贝 memcpy内存拷贝,没有问题;memmove,内存移动?错,如果这样理解的话,那么这篇文章你就必须要好好看看了,memmove还是内存拷贝.那么既然memcpy和memmove二者 ...