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?

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[110];
int dp[110][110][110];
int main()
{
    //freopen("in.txt","r",stdin);
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        scanf("%d",d);d[1]=0;
        rep(i,2,n) scanf("%d",&d[i]);
        rep(i,2,n) d[i]+=d[i-1];
        rep(i,0,n) rep(j,0,n) rep(k,0,n) dp[i][j][k]=-1e8;
        dp[0][0][0]=0;
        rep(i,1,n)
        {
            dp[i][0][0]=0;
            rep(j,1,i)
            {
                rep(k,0,j) dp[i][j][k]=dp[i-1][j][k];
                rep(k,1,j) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k-1]-2*d[i]+d[0]); //在该点设从左向右掉头的检查站
                rep(k,0,j-1) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k+1]+2*d[i]+d[0]); //在该点设从右向左掉头的检查站
                rep(k,0,j) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k]);            //在该点设不需掉头的检查站
            }
        }
        printf("%d\n",dp[n][m][0]);
    }
    return 0;
}
时间: 2024-10-28 19:39:13

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

反思2017CCPC网络赛

很遗憾,经历了一个月的集训(7.20-8.18),我们小队在网络赛收获了0题,这... 此刻,我想到的只有担当.我们小队是一体的,每个人的能力都关乎着小队的成绩,所以我有责任做好我的事,我有责任为这个团队带来荣誉. 所以,我会搞好ACM.时间会证明一切. 担当 担当 担当

2016大连网络赛 1008 &amp; hdu5875 (优先队列+离线)=不确定暴力

题意:给你一个区间,求a_l%a_(l+1)%a_(l+2)%-%a_r 的值 分析:听说一个数在给定区间中只有不是很多的位置可一连续对它求模,所以想到一个比较暴力有可行的方法,猜想复杂度应该是nlogn.具体是这样的,从左到有枚举每个位置, L[]记录[1,r]中所有元素连续取模到r的值.一开始把a[1]加进优先队列pq,对于第二位置,若pq.top()>=a[i],取出并取模,然后更新对应的位置l的答案,并把取模后答案插入优先队列,然后处理有区间是2的所有询问.对于第i个位置,若pq.top

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 on the string.There are two types of queries:1. Flipping the bits (i.e., changing all 1 to 0 and 0 to 1) between l and r (inclusive).2. Counting the

hdu 5014 Number Sequence(西安网络赛1008)

Number Sequence                                                                  Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 633    Accepted Submission(s): 300 Special Judge Problem Descrip

2019 CCPC网络赛

一到网络赛,大家都是东亚之光 1001 00:23:46 solved by hl 签到 枚举一下位就行了 #include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <vector> #include <string> #include <bitset

2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛

Banana Bananas are the favoured food of monkeys. In the forest, there is a Banana Company that provides bananas from different places. The company has two lists. The first list records the types of bananas preferred by different monkeys, and the seco

hdu6153 A Secret CCPC网络赛 51nod 1277 KMP

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意: 给出两个字符串S1,S2,求S2的所有后缀在S1中出现的次数与其长度的乘积之和. 思路: CCPC网络赛题解: https://post.icpc-camp.org/d/714-ccpc-2017 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1277   是一样的 将s1,s2翻转,转化为求前缀在s1中出

2015长春网络赛总结

早上七点多就(冻)醒来了,训练了一个暑假,acm生涯的第一场网络赛,很激动. 九点开打,我拔不出网线,用的机房电脑,装的cb有问题,不能编译,只好用dev.男神电脑插上网线没有网,习惯了linux可能不习惯吧.这提醒我们以后一定要早点去把环境调好. 第三分钟,G题有人A了.我跟560开始看题,男神还在弄电脑.题意是给你n个数(n<1000),然后q(q<1000)次询问,要求你输出[l,r]区间的最大值.数据很小,我说暴力,然后560说线段树,然后模板13分钟1Y.然后560开始搞J,一个貌似

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结