//============================================================================
// 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;
}
Mines in DP
最新推荐文章于 2019-08-06 10:51:20 发布
本文深入探讨了动态规划(DP)在解决复杂问题中的应用,通过实例解析如何利用DP来求解‘扫雷’类问题,揭示其背后的思路与技巧,帮助读者深化对动态规划理解。
摘要由CSDN通过智能技术生成