The Karting 2017ccpc网络赛 1008
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?
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).
#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的更多相关文章
- HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 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 ...
- HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)
Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...
- 2017青岛网络赛1008 Chinese Zodiac
Chinese Zodiac Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- HDU 5875 Function -2016 ICPC 大连赛区网络赛
题目链接 网络赛的水实在太深,这场居然没出线zzz,差了一点点,看到这道题的的时候就剩半个小时了.上面是官方的题意题解,打完了才知道暴力就可以过,暴力我们当时是想出来了的,如果稍稍再优化一下估计就过了 ...
- 大连网络赛 1006 Football Games
//大连网络赛 1006 // 吐槽:数据比较水.下面代码可以AC // 但是正解好像是:排序后,前i项的和大于等于i*(i-1) #include <bits/stdc++.h> usi ...
- 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree
// 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree // 题意:n个点的树,每个节点有权值为正,只能用一次,每条边有负权,可以 ...
- (四面体)CCPC网络赛 HDU5839 Special Tetrahedron
CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...
- HDU-4041-Eliminate Witches! (11年北京网络赛!!)
Eliminate Witches! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- css动画属性--小球移动
主体只有一个div <body> <div></div> </body> 样式部分(测试:目前的浏览器还是需要加前缀才能兼容) <style> ...
- Ambari安装之安装并配置Ambari-server(三)
前期博客 Ambari安装之部署本地库(镜像服务器)(二) 安装并配置Ambari-server (1)检查仓库是否可用 [hadoop@ambari01 yum.repos.d]$ pwd /et ...
- centos7下编译安装mysql
推荐: http://www.cnblogs.com/yunns/p/4877333.html
- PHP通过phpmailer批量发送邮件功能
前端页面代码: 注意:目前发送人使用的qq邮箱支持的不是特别友好.建议使用网易 新浪 163等其他邮箱. 需要用到phpmailer包 下载地址:https://sourceforge.net/pro ...
- angularJS的$http.post请求,.net后台接收不到参数值的解决方案
JS通用部分 var shoppingCartModule =angular.module('starter', ['ionic'], function ($httpProvider) { // Us ...
- PythonTip--一马当先--bfs
刚学python,小试牛刀 一马当先 讨论此题 | 解题报告 顶(39) (AC/Submit)Ratio(477|1829)26.08% 踩(1) 描述: 下过象棋的人都知道,马只能走'日'字形(包 ...
- vue指令v-cloak示例解析
v-cloak会隐藏未编译的 Mustache 标签,直至实例准备完毕: [v-cloak] { display: none; } <div v-cloak> {{ message }} ...
- android.intent.action.MAIN与android.intent.category.LAUNCHER
android.intent.action.MAIN 决定应用程序最先启动的Activity android.intent.category.LAUNCHER 决定应用程序是否显示在程序列表里 在网上 ...
- HTML中的target标记
HTML:target=_blank -- 在新窗口中打开链接 _parent -- 在父窗体中打开链接 _self -- 在当前窗体打开链接,此为默认值 _top -- 在当前窗体打开链接,并替换当 ...
- uiautomator +python 实现安卓自动化
很多人看到这个题目我相信他们可能会说,uiautomator不是java开发的吗?python怎么用呢,其实呢 ,一开始我也是这么想的,看了金阳光老师的视频,也是用java写的,我表示不服,我要科学上 ...