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
看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...
随机推荐
- ARM Linux 3.x的设备树(Device Tree)【转】
转自:http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1. ...
- BZOJ4840 NEERC2016 Binary Code
Problem BZOJ Solution 可能是因为快要省选了,所以最近更博的频率好像高了点_(:зゝ∠)_ 每个字符串最多有两个状态,然后要满足一些依赖关系,考虑2sat.可以先把字符串的结束节点 ...
- wiki confluence安装
注意:安装前请先确认内存 至少2G 1.上传 atlassian-confluence-5.9.3-x64.bin 文件,修改权限 chmod 777 atlassian-confluence-5.9 ...
- Linux入门(一)root密码设置和用户切换
从这学期开始,本人将会亲自开一个Linux 专题学习包括Linux 常用命令,常见问题的一些解决方法,以及Linux系统下C和C++一些学习经验 下面这张图片是首次安装Ubuntu后第一次设置root ...
- HDU 1507 Uncle Tom's Inherited Land(最大匹配+分奇偶部分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 题目大意:给你一张n*m大小的图,可以将白色正方形凑成1*2的长方形,问你最多可以凑出几块,并输 ...
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
用SQL语句添加删除修改字段 1.增加字段 alter table docdsp add dspcode char(200) 2.删除字段 ALTER TABLE table_NAME DROP CO ...
- 20155309南皓芯 实验2 Windows口令破解
在网络界,攻击事件发生的频率越来越高,其中相当多的都是由于网站密码泄露的缘故,或是人为因素导致,或是口令遭到破解,所以从某种角度而言,密码的安全问题不仅仅是技术上的问题,更主要的是人的安全意识问题. ...
- CVE-2013-0025
Microsoft IE ‘SLayoutRun’释放后重用漏洞(CNNVD-201302-197) Microsoft Internet Explorer是微软Windows操作系统中默认捆绑的WE ...
- PowerTool x64驱动模块逆向分析(持续更新)
比赛打完了,来继续搞了,因为那个主动防御正在写,所以想找找思路正好想到可以来逆向一下PT的驱动模块看看pt大大是怎么写的程序. PT x64版本的驱动模块是这个kEvP64.sys. 0x0 先来看看 ...
- centos安装lspci工具
https://blog.csdn.net/wudiyi815/article/details/38325199