Presents in Bankopolis (区间dp)

Presents in Bankopolis

[Link](Problem - D - Codeforces)

题意

​ 给你一个有向图,找一条恰好经过 k k k个点的最短路径,并且要求每次选的边不能跃过之前已经经过的结点。即对于路径中的边 x → y x\to y xy,不存在以前经过的点 t t t使得三者编号满足 m i n ( x , y ) ≤ t ≤ m a x ( x , y ) min(x,y)\le t\le max(x,y) min(x,y)tmax(x,y)

思路

​ 一开始写了个暴力的搜索, T 9 T9 T9。转化一下题意就等价于在一个长度为 n n n的数轴上,从某个点开始走 k − 1 k-1 k1步的最短距离,并且当前走的区间不能包含住前面走的点,只有两种走法,往外或者往里,这样区间应该是不断缩小的,我们可以反向思考它,由小的区间往外走,可以用 f [ k ] [ i ] [ j ] [ s ] : 当 前 走 了 k 步 的 区 间 左 端 点 在 l 右 端 点 r 且 s = 0 表 示 当 前 在 左 边 s = 1 表 示 当 前 在 右 边 的 最 短 路 径 f[k][i][j][s]:当前走了k步的区间左端点在l右端点r且s=0表示当前在左边s=1表示当前在右边的最短路径 f[k][i][j][s]:klrs=0s=1,第一维可以优化掉,做区间 d p dp dp即可,转移满足包含当前区间或者不相交即可。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> k >> m;
    vector<PII> g[n + 1];
    for (int i = 1; i <= m; i ++) {
        int x, y, z; cin >> x >> y >> z;
        g[y].push_back({x, z});
    }
    vector<vector<vector<int>>> f(n + 1, vector<vector<int>>(n + 1, vector<int>(2, INF)));
    for (int i = 1; i <= n; i ++) f[i][i][0] = f[i][i][1] = 0;

    for (int i = 0; i < k - 1; i ++) {
        vector<vector<vector<int>>> nf(n + 1, vector<vector<int>>(n + 1, vector<int>(2, INF)));
        for (int l = 1; l <= n; l ++)
            for (int r = l; r <= n; r ++) {
                if (f[l][r][0] != INF) {
                    for (auto t : g[l]) 
                        if (t.first < l || t.first > r) {
                            int k1 = min(t.first, l), k2 = max(t.first, r);
                            bool ok = (t.first == k2);
                            nf[k1][k2][ok] = min(nf[k1][k2][ok], f[l][r][0] + t.second);  
                        }                
                       
                }
                if (f[l][r][1] != INF) {                             
                    for (auto t : g[r])
                        if (t.first > r || t.first < l) {
                            int k1 = min(t.first, l), k2 = max(t.first, r);
                            bool ok = (t.first == k2);
                            nf[k1][k2][ok] = min(nf[k1][k2][ok], f[l][r][1] + t.second);
                        }
                       
                }                               
            }
                        
        f = nf;                            
    }

    int res = INF;
    for (int i = 1; i <= n; i ++)
        for (int j = i; j <= n; j ++)
            res = min(res, min(f[i][j][0], f[i][j][1]));

    if (res == INF) res = -1;
    cout << res << '\n';
    return 0;
}
### In-Sensor Zoom Technology Overview In-sensor zoom technology refers to the ability of an imaging sensor to dynamically adjust its active pixel region for zooming purposes without requiring additional optical components. This technique leverages the high-resolution capabilities of modern sensors to crop and scale images in real-time, providing a digital zoom effect that minimizes quality degradation[^1]. The implementation of in-sensor zoom involves several key aspects, including hardware design, firmware optimization, and software integration. #### Hardware Design Considerations The design of the imaging sensor plays a critical role in enabling effective in-sensor zoom. Sensors with higher resolutions offer more flexibility in selecting regions of interest (ROIs) for cropping and scaling. Advanced CMOS sensors often include features such as programmable ROI selection and on-chip processing units that facilitate real-time zoom operations[^2]. These sensors can be configured to output cropped images directly, reducing the computational burden on downstream processors. ```python # Example of configuring a sensor for ROI selection def configure_sensor_roi(sensor, width, height, x_offset, y_offset): """ Configures the sensor's region of interest (ROI). Args: sensor (object): Sensor object. width (int): Width of the ROI. height (int): Height of the ROI. x_offset (int): X-axis offset of the ROI. y_offset (int): Y-axis offset of the ROI. """ sensor.set_roi(width=width, height=height, x=x_offset, y=y_offset) ``` #### Firmware Optimization Techniques Firmware plays a crucial role in optimizing the performance of in-sensor zoom. Efficient algorithms are implemented to handle tasks such as ROI selection, image scaling, and noise reduction. Techniques like bilinear interpolation or more advanced methods such as Lanczos resampling can be employed to maintain image quality during scaling operations[^3]. Additionally, firmware optimizations can reduce power consumption and improve latency, making the system suitable for real-time applications. #### Software Integration Challenges Integrating in-sensor zoom functionality into software systems presents several challenges. Developers must ensure seamless interaction between the sensor driver, image processing libraries, and application layers. For instance, when using tools like Puppeteer for web automation, integrating in-sensor zoom may require custom modifications to handle image data efficiently[^4]. ```javascript // Example of handling image data in Puppeteer const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ headless: false, defaultViewport: { width: 1200, height: 900 }, ignoreDefaultArgs: ["--enable-automation"] }); const page = await browser.newPage(); await page.goto('https://example.com'); const screenshot = await page.screenshot({ path: 'screenshot.png' }); await browser.close(); })(); ``` #### Tutorials and Resources For developers interested in implementing in-sensor zoom, several resources are available. Academic papers and conference proceedings, such as those presented at ICLR, provide insights into the latest advancements in deep learning techniques applied to boundary detection and image processing[^5]. Additionally, practical guides and code examples can be found in developer communities and forums, offering step-by-step instructions for integrating these technologies into various platforms.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值