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. 使用express, create-react-app, mongodb搭建react模拟数据开发环境

    提要 最近刚刚完成了一个vue的项目,其中涉及的用户数有6000多个以及其他数据也比较多,为了在前端能够真实的进行数据模拟,所有把全量数据拷贝下来放到了api.json中.这样导致整个api.json ...

  2. 初学angular

    1.angular   表达式 2.ng-app   ng-init  ng-model  ng-repeat ng-model是用于表单元素的,支持双向绑定.对普通元素无效: ng-bind用于普通 ...

  3. 教你做一个单机版人事管理系统(Winform版)treeview与listview使用详情

    ------------------------------------------------------------------部门部分------------------------------ ...

  4. Jmeter使用代理服务器录制脚本

    Mark一下Jmeter使用代理服务器录制脚本,以备自己可以翻阅,也可以帮助其他人了解一下Jmeter的这个功能.其实录制脚本只是在我们工作中的一个小插曲而已,只是为了能快速看到应用程序跑的逻辑及实现 ...

  5. selenium3.x 踏坑记

    Selenium 3.x 出来也有段时间了,有哪些坑呢? 有好长一段时间没有用selenium了.最近想用来做个web自动化的小工具.根据以往经验,firefox是不需要下载driver的.启动fir ...

  6. Experience of Python Learning Week 1

    1.The founder of python is Guido van Rossum ,he created it on Christmas in 1989, smriti of ABC langu ...

  7. 浅谈Vue不同场景下组件间的数据交流

    浅谈Vue不同场景下组件间的数据“交流”   Vue的官方文档可以说是很详细了.在我看来,它和react等其他框架文档一样,讲述的方式的更多的是“方法论”,而不是“场景论”,这也就导致了:我们在阅读完 ...

  8. Linux(2)文件和权限

    用户目录 位于/home/user, 称为用户目录或家目录, 表示方法: /home/user ~ 相对路径和绝对路径 绝对路径 从 / 目录开始描述的路径外绝对路径 cd /home cd /usr ...

  9. ubuntu中ssh自启动

    打开/etc/rc.local文件,在exit 0语句前加入: /etc/init.d/ssh start(前提是本身的启动方法是这样的才可以) 或者/usr/local/sbin/sshd(我使用的 ...

  10. Oracle RAC 实验环境RMAN备份v1.01

    Oracle RAC 实验环境RMAN备份v1.01 环境:RHEL 6.5 + Oracle GI 11.2.0.4 + RAC 11.2.0.4 (2 nodes) 需求:制定RAMN备份策略 版 ...