Codeforces 313D Ilya and Roads【Dp+思维】

针对一条包含多个洞的道路,本文介绍了一种算法来确定修复至少K个洞所需的最小花费。通过动态规划的方法,预处理出修复任意两个洞之间的最小成本,并利用这些信息有效地解决了问题。

D. Ilya and Roads
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as n holes in a row. We will consider the holes numbered from 1 to n, from left to right.

Ilya is really keep on helping his city. So, he wants to fix at least k holes (perharps he can fix more) on a single ZooVille road.

The city has m building companies, the i-th company needs ci money units to fix a road segment containing holes with numbers of at least li and at most ri. The companies in ZooVille are very greedy, so, if they fix a segment containing some already fixed holes, they do not decrease the price for fixing the segment.

Determine the minimum money Ilya will need to fix at least k holes.

Input

The first line contains three integers n, m, k (1 ≤ n ≤ 300, 1 ≤ m ≤ 105, 1 ≤ k ≤ n). The next m lines contain the companies' description. The i-th line contains three integers li, ri, ci (1 ≤ li ≤ ri ≤ n, 1 ≤ ci ≤ 109).

Output

Print a single integer — the minimum money Ilya needs to fix at least k holes.

If it is impossible to fix at least k holes, print -1.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples
Input
10 4 6
7 9 11
6 9 13
7 7 7
3 5 6
Output
17
Input
10 7 1
3 4 15
8 9 8
5 6 8
9 10 6
1 4 2
1 4 10
8 10 13
Output
2
Input
10 1 9
5 10 14
Output
-1


题目大意:

给你N个洞,需要进行填补至少K个,现在有M个施工队,对于这M个施工队的元素有三个:

L,R,C.表示这个施工队只能对于区间【L,R】的洞进行填补,雇佣这个施工队就需要花费C单位的价钱。

问至少填补K个洞的最小花费。


思路:


显然直接贪心是不可取的,我们考虑Dp.对于Dp来讲,对于最终结果的无非有三种状态:

①位子

②填补了多少个洞

③花费为多少。

那么我们设定Dp【i】【j】表示为从左到右的Dp,到位子i,一共填补了j个洞口的最小花费。


那么状态转移过程我们可以O(n*k*m)去求,然而时间复杂度不允许;

所以我们要优化这个m.观察到数据范围N不大,所以我们考虑预处理出cost【i】【j】表示填补区间【i,j】的洞口的最小花费.

因为是线性的动态规划,所以预处理cost【i】【j】的时候没有必要O(m*n^2)去做,直接O(m*n*2)的以左右端点各作为起点和终点去画一段即可:



那么状态转移方程就可以O(n^3)的去转移:




注意实现代码的细节就没有别的难点了。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
struct node
{
    int x,y;
    ll w;
}a[100040];
ll cost[305][305];
ll dp[305][305];
const ll INF=100000000000000000;
int main()
{
    int n,m,kk;
    while(~scanf("%d%d%d",&n,&m,&kk))
    {
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                cost[i][j]=INF;
                dp[i][j]=INF;
            }
        }
        for(int i=1;i<=m;i++)
        {
            int x,y,w;
            scanf("%d%d%I64d",&a[i].x,&a[i].y,&a[i].w);
            for(int j=a[i].x;j<=a[i].y;j++)
            {
                cost[j][a[i].y]=min(cost[j][a[i].y],a[i].w);
                cost[a[i].x][j]=min(cost[a[i].x][j],a[i].w);
            }
            cost[a[i].x][a[i].y]=min(cost[a[i].x][a[i].y],a[i].w);
        }
        dp[0][0]=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=i;j++)
            {
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
                for(int k=1;k<=i;k++)
                {
                    if(j-(i-k+1)>=0)
                    {
                        dp[i][j]=min(dp[i][j],cost[k][i]+dp[k-1][j-(i-k+1)]);
                    }
                }
            }
        }
        if(dp[n][kk]==INF)printf("-1\n");
        else
        printf("%I64d\n",dp[n][kk]);
    }
}





内容概要:本文介绍了一个基于MATLAB实现的无人机三维路径规划项目,采用蚁群算法(ACO)与多层感知机(MLP)相结合的混合模型(ACO-MLP)。该模型通过三维环境离散化建模,利用ACO进行全局路径搜索,并引入MLP对环境特征进行自适应学习与启发因子优化,实现路径的动态调整与多目标优化。项目解决了高维空间建模、动态障碍规避、局部最优陷阱、算法实时性及多目标权衡等关键技术难题,结合并行计算与参数自适应机制,提升了路径规划的智能性、安全性和工程适用性。文中提供了详细的模型架构、核心算法流程及MATLAB代码示例,涵盖空间建模、信息素更新、MLP训练与融合优化等关键步骤。; 适合人群:具备一定MATLAB编程基础,熟悉智能优化算法与神经网络的高校学生、科研人员及从事无人机路径规划相关工作的工程师;适合从事智能无人系统、自动驾驶、机器人导航等领域的研究人员; 使用场景及目标:①应用于复杂三维环境下的无人机路径规划,如城市物流、灾害救援、军事侦察等场景;②实现飞行安全、能耗优化、路径平滑与实时避障等多目标协同优化;③为智能无人系统的自主决策与环境适应能力提供算法支持; 阅读建议:此资源结合理论模型与MATLAB实践,建议读者在理解ACO与MLP基本原理的基础上,结合代码示例进行仿真调试,重点关注ACO-MLP融合机制、多目标优化函数设计及参数自适应策略的实现,以深入掌握混合智能算法在工程中的应用方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值