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 ...
随机推荐
- C# 设计模式之空对象模式
最近看了不少的书籍和视频等相关资料,决定自己边学习边写一下个人对设计模式的理解,如果有不对的请大家多多指正. 今天先说说我个人觉得最简单的设计模式 -- [空对象模式] 空对象模式可以减少客户端对对象 ...
- git - 远程分支
对于用户来说,git给人提交到本地的机会.我们可以在自己的机器上创建不同的branch,来测试和存放不同的代码. 对于代码管理员而言,git有许多优良的特性.管理着不同的分支,同一套源代码可以出不一样 ...
- [转]从入门到精通: 最小费用流的“zkw算法”
>>>> 原文地址:最小费用流的“zkw算法” <<<< 1. 网络流的一些基本概念 很多同学建立过网络流模型做题目, 也学过了各种算法, 但是对于基本 ...
- form表单提交图片禁止跳转
问题: 最近在做项目时,遇到上传图片需求,且在不跳转的情况下获取到返回信息 思路: 1. 使用ajax发送异步请求,经多次测试,最终以失败告终 2. iframe 禁止跳转(未尝试) 3. 修改fo ...
- Spark No FileSystem for scheme file 解决方法
在给代码带包成jar后,放到环境中运行出现如下错误: Exception in thread "main" java.io.IOException: No FileSystem f ...
- [补档][Jxoi2012] 奇怪的道路
[Jxoi2012] 奇怪的道路 题目 传送门 :http://www.lydsy.com/JudgeOnline/problem.php?id=3195 小宇从历史书上了解到一个古老的文明.这个文明 ...
- 15. leetcode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1 ...
- Ubuntu系统的安装Sublime3
1.添加Sublime-text-3软件包的软件源 sudo add-apt-repository ppa:webupd8team/sublime-text-3 2.使用以下命令更新系统软件源 ...
- NYOJ--114--某种序列(大数)
某种序列 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 数列A满足An = An-1 + An-2 + An-3, n >= 3 编写程序,给定A0, A1 ...
- 万能头文件#include
#include<bits/stdc++.h>包含了目前c++所包含的所有头文件!!!! 测试结果POJ不支持HDU,NYOJ支持