The Karting championship will be held on a straight road. There are N keypoints on the road. The path between keypoint i and i+1 has a degree of difficulty Di(Di may be negative if the path is too smooth). Now the Organizers want to darw up some routes among these keypoints(The number of routes can be many to avoid a boring match). The organizers will choose some checkpoints from the keypoints for the routes(Each route shold include at least two checkpoints, and each keypoint can not be chosen as checkpoint more than once. Two routes can not share one checkpoint). The players should drive their karts to pass the checkpoints in the given order and return to the first checkpoint.

For example, if there are 4 checkpoints 1,3,2,4 in order in a route, players shold drive pass keypoint 1,2,3,2,3,4,3,2,1 in order. In this example, the players should make a 180 degree turn 4 times in the route(When players return to checkpoint 1, they also need to make a 180 degree turn). Makeing a 180 degree turn also has a degree of difficulty D0. The difficulty of a route is defined as follow. The initial difficluty is 0. Each time the players in the route need to pass the path between keypoint i and i+1, the difficulty shold increase Di, and each time the players need to make a 180 degree turn, the difficulty should increase D0.

To make the championship more exciting, the organizers want to maximize the sum of difficulty of all routes. They will choose exactly M keypoints to set up checkpoints. So what is the maximum sum of difficulty of all routes?

Input
There are multiple test cases. 
The first line of each test case contains two integers N and M(2<=M<=N<=100). 
The second line contains N integers D0,D1,D2,...,Dn-1(-100<=Di<=100).
 
Output
One integer in a single line for each test case, the maximum sum of difficulty of all routes.
 
建模:
dp[i][j][k]表示考虑到了第i个点,选了j个检查站,左检查站比右检查站的个数的差值为k时的情况。(此处右检查站表示车行驶到该处先------>再<----)
状态转移有三种可能:
1.点i被选作右检查站,那么对答案贡献2*d[i]+d[0],d[i]此处表示从最左边行驶到i处的困难度的和。
2.点i被选作左检查站,对答案贡献为-2*d[i]+d[0]
3.点i被选作可直行的检查站,对答案无影响
 
由于对i从左往右扫描,左检查站总是比右检查站多,故不用考虑k为负。
 
代码如下:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
int d[];
int dp[][][];
int main()
{
//freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m)==)
{
scanf("%d",d);d[]=;
rep(i,,n) scanf("%d",&d[i]);
rep(i,,n) d[i]+=d[i-];
rep(i,,n) rep(j,,n) rep(k,,n) dp[i][j][k]=-1e8;
dp[][][]=;
rep(i,,n)
{
dp[i][][]=;
rep(j,,i)
{
rep(k,,j) dp[i][j][k]=dp[i-][j][k];
rep(k,,j) dp[i][j][k]=max(dp[i][j][k],dp[i-][j-][k-]-*d[i]+d[]); //在该点设从左向右掉头的检查站
rep(k,,j-) dp[i][j][k]=max(dp[i][j][k],dp[i-][j-][k+]+*d[i]+d[]); //在该点设从右向左掉头的检查站
rep(k,,j) dp[i][j][k]=max(dp[i][j][k],dp[i-][j-][k]); //在该点设不需掉头的检查站
}
}
printf("%d\n",dp[n][m][]);
}
return ;
}
 
 
 

The Karting 2017ccpc网络赛 1008的更多相关文章

  1. HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  2. Subsequence Count 2017ccpc网络赛 1006 dp+线段树维护矩阵

    Problem Description Given a binary string S[1,...,N] (i.e. a sequence of 0's and 1's), and Q queries ...

  3. HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)

    Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...

  4. 2017青岛网络赛1008 Chinese Zodiac

    Chinese Zodiac Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

  5. HDU 5875 Function -2016 ICPC 大连赛区网络赛

    题目链接 网络赛的水实在太深,这场居然没出线zzz,差了一点点,看到这道题的的时候就剩半个小时了.上面是官方的题意题解,打完了才知道暴力就可以过,暴力我们当时是想出来了的,如果稍稍再优化一下估计就过了 ...

  6. 大连网络赛 1006 Football Games

    //大连网络赛 1006 // 吐槽:数据比较水.下面代码可以AC // 但是正解好像是:排序后,前i项的和大于等于i*(i-1) #include <bits/stdc++.h> usi ...

  7. 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree

    // 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree // 题意:n个点的树,每个节点有权值为正,只能用一次,每条边有负权,可以 ...

  8. (四面体)CCPC网络赛 HDU5839 Special Tetrahedron

    CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...

  9. HDU-4041-Eliminate Witches! (11年北京网络赛!!)

    Eliminate Witches! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. hadoop 50070 无法访问问题解决汇总

    遇到这个其实不难解决! 解决办法1: [root@djt002 hadoop]# vi /etc/selinux/config 改为 SELINUX=disabled 解决办法2: 查看你的$HADO ...

  2. JavaScript 值类型和引用类型的初次研究

    今天遇到一个坑,具体的不多说,直接上代码 var a = [ [],[],[1,2,3] ] var b = ['颜色','大小','尺寸'] var arr = [] for(let i = 0; ...

  3. 谈谈localhost与127.0.0.1

    localhost意为本地主机,指这台计算机,是给回路网络接口的标准主机名,对应的IP地址为127.0.0.1,可访问本地服务器的web项目(http://localhost). 那么它们有什么区别呢 ...

  4. 初次使用Mybatis配置出现错误待解决

    数据库: create table STUDENT ( STUID NUMBER(9) not null, SNAME VARCHAR2(50) not null, SEX VARCHAR2(4), ...

  5. 一个Web 持续集成工作实践

    一个web的持续基础实践: https://mp.weixin.qq.com/src=3&timestamp=1494325174&ver=1&signature=wFVC0E ...

  6. log4j(一)——为什么要用log4j?

    一:试验环境 OS:win7 JDK:jdk7 Log4j:1.2.17(好尴尬,原本是想试验下log4j2的,结果阴差阳错用了这个版本,不过幸好,试验也不白试验,试验的作用是一样的) 二:先看两个简 ...

  7. hadoop系列三:mapreduce的使用(一)

    转载请在页首明显处注明作者与出处 http://www.cnblogs.com/zhuxiaojie/p/7224772.html 一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据的 ...

  8. node.js fs.open 和 fs.write 读取文件和改写文件

    Node.js的文件系统的Api //公共引用 var fs = require('fs'), path = require('path'); 1.读取文件readFile函数 //readFile( ...

  9. Java利用内存映射文件实现按行读取文件

    我们知道内存映射文件读取是各种读取方式中速度最快的,但是内存映射文件读取的API里没有提供按行读取的方法,需要自己实现.下面就是我利用内存映射文件实现按行读取文件的方法,如有错误之处请指出,或者有更好 ...

  10. NodeJS学习目录

    前面的话 几年前,对于学习NodeJS可能还有所迟疑,怕分散了前端学习的精力.但到了现在,如果不学习nodeJS,前端的学习却可能无法再有所进展.技术的进步就是这么残酷.对新技术观望的时候,该技术已经 ...