Working out 三维DP

本文详细解析了DP算法中的一道题目,通过转化问题视角,将复杂路径问题转化为求最大价值的问题。文章深入探讨了如何利用累积性和状态选择进行递推,并通过代码实现展示了具体的解决方案。

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

今天开始研究DP,今天是4.10 离省赛开始还有25天。
先来说一下这个题,一开始把题意看错了,没有看到必须在一个位置相遇。菜啊

这个题一开始想到了将问题转化成计算从相遇点到起点和终点的距离。
但是还是不知道怎么划分状态,看完题解后,想到了一个点就是”累积性”。联想到了概率上的分布函数,可能这就是“递推的本质”。

说一下这个题的思路。

这里写图片描述
先来说一下为什么将问题转化成相遇点到各个角的最大价值。

首先因为题目的要求必须有一个相遇点,这个很关键,一开始没翻译出来.然后假设有这样的一个点,然后可以画出几个简单的情景,或者想一下就会发现,如果只有一个相遇点的话,就会有两种情况,假设A是向左进入相遇点的话,必须从左边出相遇点,如果换方向的话,就会有另外的相遇点。
这样的话出现上面的情况,这样的话,就可以转化成各个角到相遇点的最大价值,现在就是打表算出从各个角出发到所有点的最大价值.
然后枚举所有可能的相遇点.
就可以了

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    using namespace std;
    typedef long long LL;
    const int MAXN = 1e3 + 10;
    LL dp[MAXN][MAXN][4]; // 四个方向
    LL a[MAXN][MAXN];
    void f(int n,int m)
    {
        memset(dp,0,sizeof(dp));
        for(int i = 1;i <= n; ++i)
        {
            for(int j = 1;j <= m;++j)
            {
                dp[i][j][0] = max(dp[i - 1][j][0],dp[i][j - 1][0]) + a[i][j];
            }
        }
        for(int i = n;i >= 1;--i)
        {
            for(int j = 1; j <= m;++j)
            {
                dp[i][j][1] = max(dp[i + 1][j][1],dp[i][j - 1][1]) + a[i][j];
            }
        }
        for(int i = n;i >= 1;--i)
        {
            for(int j = m;j >= 1;--j)
            {
                dp[i][j][2] = max(dp[i + 1][j][2],dp[i][j + 1][2]) + a[i][j];
            }
        }
        for(int i = 1;i <= n;++i)
        {
            for(int j = m;j >= 1;--j)
            {
                dp[i][j][3] = max(dp[i - 1][j][3],dp[i][j + 1][3]) + a[i][j];
            }
        }
    }
    int main()
    {
        ios::sync_with_stdio(false);
        int n,m;
        while(cin >> n >> m)
        {

            for(int i = 1; i <= n;i++)
            {
                for(int j = 1;j <= m;++j)
                    cin >> a[i][j];
            }
            f(n,m);
            LL ans = 0;
            for(int i = 2; i <= n - 1; ++i)
            {
                for(int j = 2;j <= m - 1;++j)
                {
                    ans = max(ans,dp[i - 1][j][0] + dp[i + 1][j][2] + dp[i][j - 1][1] + dp[i][j + 1][3]);
                    ans = max(ans,dp[i - 1][j][3] + dp[i + 1][j][1] + dp[i][j - 1][0] + dp[i][j + 1][2]);
                }
            }
            cout << ans << endl;
        }
        return 0;
    }

总 结 一 下 : 就是递推的就是 "累积“和”状态的选择和转化“ 

### 3D Object Detection ROI Head Implementation and Usage In three-dimensional (3D) object detection frameworks, Region-of-Interest Heads (ROI Heads) play an essential role similar to their counterparts in two-dimensional (2D) detectors like Faster R-CNN[^2]. An ROI Head processes candidate regions generated by a region proposal network or other means, refining these proposals into final bounding boxes with associated class labels. For 3D object detection, the input data typically includes point clouds from LiDAR sensors or depth images. The process involves several stages: #### Feature Extraction A backbone network extracts features from raw sensor inputs such as voxelized point cloud grids or multi-view images. These extracted features serve as the basis for subsequent processing steps within the ROI Head. #### Proposal Generation Proposals are generated either through dedicated networks designed specifically for 3D space—such as PointPillars—or adapted versions of traditional 2D methods applied across multiple views or slices of volumetric representations. #### Refinement via ROI Pooling/Align Operations Once proposals have been identified, they undergo refinement using operations analogous to those found in standard 2D implementations but tailored towards handling spatial information inherent in 3D datasets. This often entails applying pooling techniques that aggregate local descriptors around each proposed box location before feeding them into fully connected layers responsible for classification and regression tasks. Here’s how this might look implemented in Python code targeting PyTorch-based architectures commonly employed in modern deep learning pipelines: ```python import torch.nn.functional as F from torchvision.ops import roi_align class ROIPooler(nn.Module): def __init__(self, output_size=(7, 7), sampling_ratio=2): super().__init__() self.output_size = output_size self.sampling_ratio = sampling_ratio def forward(self, feature_maps, rois): """ Args: feature_maps (Tensor): A tensor containing all feature maps. Shape should be [batch_size, channels, height, width]. rois (List[Tensor]): List of tensors where each element corresponds to one image, holding N RoIs given as [batch_index, x1, y1, z1, x2, y2, z2]. Returns: Tensor: Pooled features corresponding to provided RoIs. Shape will be [total_num_rois, channels * H_out * W_out], assuming `output_size` was specified appropriately during initialization. """ pooled_features = [] # Iterate over individual batches/images contained within 'rois' for img_idx, per_image_roi in enumerate(rois): # Select relevant slice(s) from full set of feature maps based on current batch index selected_feature_map = feature_maps[[img_idx]] # Perform alignment operation ensuring correct mapping between original coordinates & grid cells post-extraction aligned_boxes = convert_to_normalized_coordinates(per_image_roi[:, 1:], h=feature_maps.shape[-2], w=feature_maps.shape[-1]) # Apply ROI Align function directly available within torchvision library result = roi_align(selected_feature_map, boxes=[aligned_boxes], output_size=self.output_size, spatial_scale=1., sampling_ratio=self.sampling_ratio) pooled_features.append(result.flatten(start_dim=1)) return torch.cat(pooled_features) def convert_to_normalized_coordinates(boxes, h, w): """Convert absolute coordinate values into normalized form suitable for use with ROI align.""" new_boxes = boxes.clone() new_boxes[..., :2] /= w new_boxes[..., 2:] /= h return new_boxes ``` This example demonstrates basic functionality required when implementing custom ROI heads suited for working with 3D objects represented via structured grids derived from point clouds or stereo vision systems. Note that actual deployment scenarios may require additional considerations depending upon specific application requirements and hardware constraints present at runtime.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值