Codeforces Round #243 (Div. 2)——Sereja and Swaps
来源:互联网 发布:淘宝衣服女装夏装 编辑:程序博客网 时间:2024/05/22 10:42
题目链接
- 题意:
给定一个整数序列长度为n,可以至多交换k次,求最大连续区间和(1 ≤ n ≤ 200; 1 ≤ k ≤ 10) - 分析:
自己上来先考虑的方向是:先找出最大连续区间和,然后逐个交换,但是这样没法处理。对于最大区间内的交换直接找出最小值即可,但是如果最优位置不在当前区间内,情况就不好处理了
根据上述特点,方向应该是,固定区间长度,然后进行交换。这样的复杂度是O(n^3),对于数据可以接受
const int MAXN = 210;int ipt[MAXN], ta[MAXN], tb[MAXN];int main(){// freopen("in.txt", "r", stdin); int n, m; while (~RII(n, m)) { FE(i, 1, n) RI(ipt[i]); int ans = -INF; FE(i, 1, n) FE(j, i, n) { int t1 = 0, t2 = 0; FE(k, i, j) ta[t1++] = ipt[k]; FE(k, 1, i - 1) tb[t2++] = ipt[k]; FE(k, j + 1, n) tb[t2++] = ipt[k]; sort(ta, ta + t1); sort(tb, tb + t2); reverse(tb, tb + t2); int e = min(min(m, t1), t2); REP(k, e) ta[k] = max(ta[k], tb[k]); int sum = 0; REP(k, t1) sum += ta[k]; ans = max(ans, sum); } WI(ans); } return 0;}
4 0
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #243 (Div. 2)-C. Sereja and Swaps(multiset)
- Codeforces Round #243 (Div. 1) A Sereja and Swaps
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps 解题报告
- Codeforces Round #243 (Div. 2)——Sereja and Table
- Codeforces Round #243 (Div. 1)——Sereja and Squares
- Codeforces Round #243 (Div. 2)——A. Sereja and Mugs
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
- Codeforces Round #223 (Div. 2)——B. Sereja and Stairs
- Codeforces Round #223 (Div. 2)——A. Sereja and Dima
- Codeforces Round #252 (Div. 2)441D. Valera and Swaps
- Codeforces Round #243 (Div. 1) B Sereja and Table
- Codeforces Round #243 (Div. 1) C Sereja and Two Sequences
- Codeforces Round #215 (Div. 2) -A. Sereja and Coat Rack
- Codeforces Round #215 (Div. 2) -B. Sereja and Suffixes
- haproxy 配置 说明
- codeforces 426/A
- Java 5种字符串拼接方式性能比较。
- [Code Jam] Bribe the Prisoners
- android AsyncTask
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
- C++ string_demo
- 揭秘SNS自主创业军团 军团高层月赚10万元不是问题
- MongoDB基本命令
- 阵列源码学习实践(一)阵列的开机自动检测
- spring中配置<aop:aspectj-autoproxy/>与<mvc:annotation-driven/>作用以及国际化配置
- AndroidPN环境建立
- 公司内网发帖测试
- J2ME内存优化方法