D. Top Secret Task
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line of the input contains three positive integers nks (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.

Output

Print a single integer — the minimum possible total loquacity of the top-secret troop.

Sample test(s)
input
3 2 2
2 4 1
output
3
input
5 4 2
10 1 6 2 5
output
18
input
5 2 3
3 1 4 2 5
output
3
Note

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:

  1. (10, 1, 6 — 2, 5)
  2. (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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #327 (Div. 2) E. Three States

    题目链接: 题目 E. Three States time limit per test:5 seconds memory limit per test:512 megabytes 问题描述 The ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

  8. Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing

    http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...

  9. 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 ...

随机推荐

  1. 警告: 隐式声明与内建函数‘exit’不兼容 [默认启用]

    警告: 隐式声明与内建函数‘exit’不兼容 [默认启用] 最近在学习linux下的多任务编程,用到exit等函数时,经常出现该警告,查找资料后发现,原因其实很简单,没有把stdlib.h头文件包含进 ...

  2. js中的函数,Date对象,Math对象和数组对象

    函数就是完成某个功能的一组语句,js中的函数由关键字 function + 函数名 + 一组参数定义;函数在定义后可以被重复调用,通常将常用的功能写成一个函数,利用函数可以使代码的组织结构更多清晰. ...

  3. 根据请求头跳转判断Android&iOS

    if(navigator.userAgent.match(/Android/i)) { window.location = 'http://apk.hiapk.com/m/downloads?id=c ...

  4. 控制uibutton的title范围

    moreBtn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 10);

  5. Nicholas C. Zakas(JS圣经:JavaScript高级程序设计作者)如何面试前端工程师

    Original Post:Interviewing the front-end engineerNicholas C. Zakas,2010年1月5日翻译完成:2010年1月7日,最后更新:2010 ...

  6. 手游2dx面试笔记一

    第一轮IQ测试:都来面试程序了,相信IQ再怎么也坑不到哪里去吧.要问什么样的题,几页纸呐, 如:1.找出不同类:羚羊.斑马.鲨鱼 2.在()里添一字使2边都能组词:木()料 3.中间值?:1,2,4, ...

  7. FIR滤波器设计

    FIR滤波器的优越性: 相位对应为严格的线性,不存在延迟失真,仅仅有固定的时间延迟: 因为不存在稳定性问题,设计相对简单: 仅仅包括实数算法,不涉及复数算法,不须要递推运算,长度为M,阶数为M-1,计 ...

  8. cocos2d-x 2.x 图层特效Effect(转)

    CCSprite* sp = CCSprite::create("Default.png"); sp->setPosition(ccp(, )); addChild(sp); ...

  9. 作业三 ATM

    模拟实现一个ATM+购物商场程序 1.额度15000自定义 商城和银行两个帐户 2.实现购物商城,买东西加入购物车,调用信用卡接口结账 3.可以提现,手续费5%,提现额度不能超过50% 4.每月22日 ...

  10. django: form fileupload - 2

    继续介绍文件上传的第二种形式和第三种形式. ------------------------------------------------------------- 第二种形式较简单,直接用 DB ...