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 ...
随机推荐
- 双外边距浮动bug;3像素文本偏移bug;IE6以下相对定位中的绝对定位bug
http://www.cnblogs.com/star91/p/5458100.html
- DevExpress之列表控件
listBoxControl和checkedListBoxControl 常用属性 DataSource---------数据源 DisplayMember-----默认显示成员 这两个属性是list ...
- 【Python爬虫基础】抓取知乎页面所有图片
抓取地址所有图片 #! /usr/bin/env python from urlparse import urlsplit from os.path import basename import ur ...
- swift菜鸟入门视频教程-04-集合类型
本人自己录制的swift菜鸟入门,欢迎大家拍砖,有什么问题能够在这里留言. 主要内容: 数组(Arrays) 字典(Dictionaries) 集合的可变性(Mutability of Collect ...
- TCP/IP具体解释--三次握手和四次握手 Dos攻击
TCP连接的状态图 TCP建立连接的三次握手过程,以及关闭连接的四次握手过程 贴一个telnet建立连接,断开连接的使用wireshark捕获的packet截图. 1.建立连接协议(三次握手) (1) ...
- c++大作业--学籍管理系统--
1.题目描写叙述 学籍管理系统: 依据信息管理系统的业务流程.要求以及所要实现的目标,完毕下面功能: (1)建立学生档案的管理和维护.实现计算机自己主动化管理体制. (2)建立学生成绩管理机制,在计算 ...
- java byte 16进制转换
整型转16进制: int devIdInt = Integer.parseInt(devId);String devIdString = Integer.toHexString(devIdInt); ...
- IE下判断IE版本语法使用
先摆一下判断IE版本语法 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![ ...
- WEB服务健康状态检测
#!/bin/sh #date:2015-12-07 #filename:check_web.sh #作者:lixingli #Email:1162572407@qq.com #version:v1. ...
- SVN 代码下载,上传
代码下载,如: svn co https://99.99.16.1:8080/svn/pavenas/webpy --username bg 代码上传,如: svn commit -m "备 ...