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 ...
随机推荐
- (转)基于企业级证书的IOS应用打包升级功能介绍
IOS应用程序升级流程介绍:IOS手机端应用程序需要升级时,打开服务器端html文件(本文为ucab.html文件)->点击在线安装->打开plist文件(本文中为ucab.plist文件 ...
- 安装orcle10g oel5.6
一.安装OEL 5.6 二.安装VMware Tools 1) 选择菜单里的VM选项,里面有一个子选项是installVMware Tools,选择它. 2) 回到操作系统,将光驱挂载到/mnt ...
- 一年后重翻javascript
回想下自己的工作历程 一年多的ios开发眨眼间就过去了 不过这一切还没有结束,紧随其后的便是前段开发,虽然顶点基础都没有,但是还是通过我的不懈努力最终成功转型,虽然刚开始是通过jq直接入门的 ...
- 【录音】Android录音--AudioRecord、MediaRecorder
Android提供了两个API用于实现录音功能:android.media.AudioRecord.android.media.MediaRecorder. 网上有很多谈论这两个类的资料.现在大致总结 ...
- Synopsys逻辑工艺库
Synopsys逻辑工艺库(DC综合) 逻辑库包括仅与综合过程有关的信息且通过DC用于设计的综合和优化. 这一信息包括引脚到引脚的时序.面积.引脚类型和功耗以及其他DC需要的必须数据. 逻辑库是一个文 ...
- (三)《Java编程思想》——构造函数初始化
1.初始化顺序是由变量在类内的定义顺序决定的,并且先初始化变量,然后才调用构造函数. package chapter4; //: OrderOfInitialization.java /** * 初始 ...
- OD: Heap in Windows 2K & XP SP1
Windows 堆溢出 MS 没有完全公开 Windows 的堆管理细节,目前对 Windows 堆的了解主要基于技术狂热者.黑客.安全专家.逆向工程师等的个人研究成果. 目前 Windows NT4 ...
- OC基础 NSDate
OC基础 NSDate #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @auto ...
- C#字符串的比较
Console.WriteLine("输入字符1"); string n1 = Console.ReadLine(); Console.WriteLine("输入字符2& ...
- C/C++中字符串存储位置
代码: #include <iostream> #include <cstdio> using namespace std; void fun(char **p){ //cha ...