标签:style blog http java color os
由于n比较小,直接暴力解决
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <functional> #include<iterator> using namespace std; int main(){ int n,k; cin >> n >> k; vector<int> a(n); for(int i = 0 ; i < n; ++ i) cin >> a[i]; int sum = accumulate(a.begin(),a.end(),0); for(int i = 0 ; i < n; ++ i){ for(int j = i ; j < n ; ++ j ){ vector<int> tmp(a.begin()+i,a.begin()+j+1); sort(tmp.begin(),tmp.end()); if(j-i+1!=n){ vector<int> b(a); b.erase(b.begin()+i,b.begin()+j+1); sort(b.begin(),b.end(),greater<int>()); for(int x =0, y = 0; b[x]>tmp[y] && x < k && x < b.size(); ++x ,++y){ tmp[y] = b[x]; } } sum = max(sum,accumulate(tmp.begin(),tmp.end(),0)); } } cout<<sum<<endl; }
Codeforces Round #243 (Div. 2) C. Sereja and Swaps,码迷,mamicode.com
Codeforces Round #243 (Div. 2) C. Sereja and Swaps
标签:style blog http java color os
原文地址:http://www.cnblogs.com/xiongqiangcs/p/3698511.html