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
看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...
随机推荐
- haproxy代理https配置方法【转】
记得在之前的一篇文章中介绍了nginx反向代理https的方法,今天这里介绍下haproxy代理https的方法: haproxy代理https有两种方式:1)haproxy服务器本身提供ssl证书, ...
- 一步一步搭建oracle 11gR2 rac+dg之共享磁盘设置(三)【转】
一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之共享磁盘准备 (三) 注意:这一步是配置rac的过程中非常重要的一步,很多童鞋 ...
- MVVM模式的命令绑定
命令绑定要达到的效果 命令绑定要关注的核心就是两个方面的问题,命令能否执行和命令怎么执行.也就是说当View中的一个Button绑定了ViewModel中一个命令后,什么时候这个Button是可用的, ...
- Apache HBase Performance Tuning 官文总结
Apache HBase Performance Tuning RAM, RAM, RAM. 不要让HBase饿死. 请使用64位的平台 必须将swapping设定为0 使用本地硬件来完成hdfs的c ...
- 数据结构之 栈 (Python 版)
数据结构之 栈 (Python 版) -- 利用线性表实现栈 栈的特性: 后进先出 基于顺序表实现栈 class SStack(): ''' 基于顺序表 实现的 栈类 ''' def __init__ ...
- java基础37 集合框架工具类Collections和数组操作工具类Arrays
一.集合框架工具类:Collections 1.1.Collections类的特点 该工具类中所有的方法都是静态的 1.2.Collections类的常用方法 binarySearch(List< ...
- android studio实现Intent通信-------牛刀小试
概述: 本博文实现一种小程序,两个Activity单向通信,主从关系,MainActivty 页面布局一个EditText+Button,实现逻辑是单击按钮将信息发送给另外一个DisplayMessa ...
- java IO流知识点总结
I/O类库中使用“流”这个抽象概念.Java对设备中数据的操作是通过流的方式.表示任何有能力产出数据的数据源对象,或者是有能力接受数据的接收端对象.“流”屏蔽了实际的I/O设备中处理数据的细节.IO流 ...
- SQLServer判断指定列的默认值是否存在,并修改默认值
SQLServer判断指定列的默认值是否存在,并修改默认值 2008年10月21日 星期二 下午 12:08 if exists(select A.name as DefaultName,B.name ...
- sqlserver中的全局变量总结
@@CONNECTIONS返回自上次启动 Microsoft? SQL Server? 以来连接或试图连接的次数.@@CPU_BUSY返回自上次启动 Microsoft? SQL Server? 以来 ...