Codeforces Round #327 (Div. 1) D. Top Secret Task
3 seconds
256 megabytes
standard input
standard output
A top-secret military base under the command of Colonel Zuev is expecting an inspection from the Ministry of Defence. According to the charter, each top-secret military base must include a top-secret troop that should... well, we cannot tell you exactly what it should do, it is a top secret troop at the end. The problem is that Zuev's base is missing this top-secret troop for some reasons.
The colonel decided to deal with the problem immediately and ordered to line up in a single line all n soldiers of the base entrusted to him. Zuev knows that the loquacity of the i-th soldier from the left is equal to qi. Zuev wants to form the top-secret troop using k leftmost soldiers in the line, thus he wants their total loquacity to be as small as possible (as the troop should remain top-secret). To achieve this, he is going to choose a pair of consecutive soldiers and swap them. He intends to do so no more than s times. Note that any soldier can be a participant of such swaps for any number of times. The problem turned out to be unusual, and colonel Zuev asked you to help.
Determine, what is the minimum total loquacity of the first k soldiers in the line, that can be achieved by performing no more than s swaps of two consecutive soldiers.
The first line of the input contains three positive integers n, k, s (1 ≤ k ≤ n ≤ 150, 1 ≤ s ≤ 109) — the number of soldiers in the line, the size of the top-secret troop to be formed and the maximum possible number of swap operations of the consecutive pair of soldiers, respectively.
The second line of the input contains n integer qi (1 ≤ qi ≤ 1 000 000) — the values of loquacity of soldiers in order they follow in line from left to right.
Print a single integer — the minimum possible total loquacity of the top-secret troop.
3 2 2
2 4 1
3
5 4 2
10 1 6 2 5
18
5 2 3
3 1 4 2 5
3
In the first sample Colonel has to swap second and third soldiers, he doesn't really need the remaining swap. The resulting soldiers order is: (2, 1, 4). Minimum possible summary loquacity of the secret troop is 3. In the second sample Colonel will perform swaps in the following order:
- (10, 1, 6 — 2, 5)
- (10, 1, 2, 6 — 5)
The resulting soldiers order is (10, 1, 2, 5, 6).
Minimum possible summary loquacity is equal to 18.
解题报告:
dp( i , j , k )表示正在考虑第 i 个数,同时已经安排了j个,用了k次交换的机会的最小值
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = + ;
int n , kk , s , q[maxn] , dp[][maxn][maxn*maxn/] , cur , errorcode , enf; void updata(int & x,int v){
x = min( x , v );
} int main(int argc,char *argv[]){
scanf("%d%d%d",&n,&kk,&s);enf = n * (n - ) / ;
for(int i = ; i < n ; ++ i) scanf("%d" , q + i);
if(s >= enf) {
sort( q , q + n);
int ans = ;
for(int i = ; i < kk ; ++ i) ans += q[i];
printf("%d\n",ans);
}
else{
memset(dp[cur] , 0x3f , sizeof(dp[cur])); errorcode = dp[cur][][];
dp[cur][][] = ;
for(int i = ; i < n ; ++ i){
int pre = cur ; cur ^= ; memset(dp[cur] , 0x3f , sizeof(dp[cur]));
for(int j = ; j <= min( i , kk ) ; ++ j){
for(int k = ; k <= s ; ++ k){
if(dp[pre][j][k]!=errorcode){
updata(dp[cur][j][k] , dp[pre][j][k]);
if(j != kk && i - j + k <= s) updata( dp[cur][j+][k + i - j] , dp[pre][j][k] + q[i] );
}
}
}
}
int ans = errorcode;
for(int i = ; i <= s ; ++ i) ans = min( ans , dp[cur][kk][i]);
printf("%d\n",ans);
}
return ;
}
Codeforces Round #327 (Div. 1) D. Top Secret Task的更多相关文章
- Codeforces Round #312 (Div. 2) E. A Simple Task 线段树
E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #327 (Div. 2) E. Three States
题目链接: 题目 E. Three States time limit per test:5 seconds memory limit per test:512 megabytes 问题描述 The ...
- Codeforces Round #327 (Div. 2) E. Three States BFS
E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...
- Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理
D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
- Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing
http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...
- Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...
随机推荐
- 远程连接mysql
win系统下,连接别人的mysql或者让别人链接自己的mysql: 打开命令行cmd 进入mysql: mysql -u root -p mysql>use mysql; mysql>s ...
- ubuntu下安装pdo扩展
ubuntu下安装好LAMP后默认情况没有安装mysql_pdo扩展,以下是安装 步聚,在终端输入以下命令 1.pecl search pdo 2.sudo pecl install pdo 当出现E ...
- JS浏览器对象-window对象
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- jq指定行切换
function G(){ var item=$('.req_list_item>li'); item.find($('.req_show')).hover(function(){ $(this ...
- 2013国内IT行业薪资对照表【技术岗】
(本文为转载,具体出处不详) 说薪水,是所有人最关心的问题.我只 想说如果想在薪水上面满意,在中国,没有哪里比垄断国企好.电力.烟草.通信才是应该努力的方向.但是像我们这种搞研发的进IT行业似乎是注定 ...
- [Javascript] Safe Nested Object Inspection
A common problem when dealing with some kinds of data is that not every object has the same nested s ...
- DFBle.swift
//// DFBle.swift// DFBle//// Created by LeeYaping on 15/9/2.// Copyright (c) 2015年 lisper. All r ...
- 好的android编码习惯
上一期分享了android内存优化的一些总结,这一期说说我认为的好的编码习惯,然后下一期会做安卓数据库优化的一些总结,逐渐的会将一些性能优化点总结分享出来,肯定是不够全面的希望不足的地方欢迎指出. 良 ...
- Python序列的方法(转)
在快速教程中,我们了解了最基本的序列(sequence).回忆一下,序列包含有定值表(tuple)和表(list).此外,字符串(string)是一种特殊的定值表.表的元素可以更改,定值表一旦建立,其 ...
- 利用css进行网页布局
网页布局: 又称版式布局,是网页UI设计师将有限的视觉元素进行有机的排列组合,将理性的思维个性的化的表现出来,是一种具有个人艺术特色的视觉传达方式.传达信息的同时有美感.网页设计特点(相对纸媒来说). ...