Mines in DP

本文深入探讨了动态规划(DP)在解决复杂问题中的应用,通过实例解析如何利用DP来求解‘扫雷’类问题,揭示其背后的思路与技巧,帮助读者深化对动态规划理解。
摘要由CSDN通过智能技术生成
//============================================================================
// Name        : CppTest.cpp
// Author      : nsos
// Version     :
// Copyright   : Your copyright notice
// Description : Hackerank in C++, Ansi-style
//============================================================================

#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

/*
https://www.hackerrank.com/contests/world-codesprint-5/challenges/mining
M=4 N=? (N<M)
5  6
15 5
20 8
25 5
35 10

#   1   2   3    4   5
1   0  60  90  120 180
2  50   0  25   50 100
3 120  40   0   40 120
4 100  50  25    0  50
5 300 200 150  100   0
  550 350 290  310 450
F(1,1,1) = 0
F(1,2,1) = 50
F(1,3,1) = 25  F(1,3,2) = 25
F(1,4,1) = 140 F(1,4,2) = 50  F(1,4,3) = 25
F(1,5,1) = 290 F(1,5,2) = 140 F(1,5,3) = 50 F(1,5,4) = 25

F(x,y,n) = min{F(x,i,j)+F(i+1,y,n-j)} 1<=x<i<y<=M, 0<=j<i-x, 0<=n-j<y-i-1
*/

int solve(vector<int> &pos, vector<int> &weight, int m, int n)
{
    int i,j;
    vector<vector<int> > score(m+1, vector<int>(m+1, 0));
    vector<vector<vector<int> > > dp(m+1, vector<vector<int> >(m+1, vector<int>(n+1, 0)));

    for (i=1; i<=m; ++i)
        for (j=1; j<=m; ++j)
            score[i][j] = abs(pos[j]-pos[i])*weight[i];
    return 0;
}

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int m,n,x,y,ret;
    cin>>m>>n;
    vector<int> pos;
    vector<int> weight;

    for (int i=0; i<m; ++i)
    {
        cin>>x>>y;
        pos.push_back(x);
        weight.push_back(y);
    }

    ret = solve(pos, weight, m, n);
    cout<<ret<<endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值