8月19号CCPC——The Karting(未解决)

本文介绍了一项卡丁车锦标赛的路线规划问题。比赛将在一条直路上进行,该路包含多个关键点,每段路径有不同的难度系数。组织者需从这些关键点中选择检查点并设计路线,使所有路线的总难度最大。玩家需按指定顺序通过检查点并返回起点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
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.
 

Sample Input
4 2
1 1 1 -1
 

Sample Output
6


欢迎大神提供思路和答案。

### 2021 CCPC Guangzhou Onsite 题目解析 #### H题: Three Integers 该题目主要考察的是分类讨论以及合理运用倍数关系的能力。当输入数据中存在一个零时,需特别注意是否存在数值为1的情况。在这种情况下,为了防止被特定测试用例攻击(即所谓的“hack”),应适当调整倍数逻辑[^1]。 以下是实现此算法的一个可能代码示例: ```cpp #include <bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; vector<int> nums={abs(a), abs(b), abs(c)}; sort(nums.begin(),nums.end()); long long res=LLONG_MAX; do{ if(nums[1]==0 && nums[2]!=0){ // 特殊情况处理 res=min(res,(long long)(nums[0]*nums[2])); } else { // 正常计算最小操作次数 long long temp=(nums[1]-nums[0]%nums[1])%nums[1]; temp += (nums[2]-nums[1]%nums[2])%nums[2]; res = min((long long)res,temp); } }while(next_permutation(nums.begin(),nums.end())); cout<<res<<"\n"; } ``` #### C题: Necklace 对于C题Necklace而言,其核心思路在于如何通过贪心策略来解决问题。具体来说,可以从第一个节点出发尝试尽可能地向右扩展路径长度;一旦遇到超出允许的最大长度`max_len`的情形,则将整个项链结构向左侧平移一定距离,从而最大化利用可用空间并减少资源浪费[^4]。 下面给出了一种基于上述思想的解决方案框架: ```cpp // 假设已知一些变量定义如 max_len, nodes 等... bool check(double mid){ double sum=0; for(auto &len:nodes){ if(sum+len<=mid){ sum+=len; } else{ return false; } } return true; } double binarySearch(){ double l=0,r=accumulate(nodes.begin(),nodes.end(),0.0); while(r-l>=EPS){ double mid=l+(r-l)/2; if(check(mid)){ r=mid-EPS; } else{ l=mid+EPS; } } return l; } ``` 以上两道典型题目展示了不同类型的解法技巧——前者依赖于细致入微的状态枚举与边界条件判断,后者则体现了经典优化理论中的动态规划与二分查找相结合的应用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值