Hello,everyone. Today is the second day,and i am fighting.You must know that dynamic programming is a flexible problem.And there is a ad problem.You want to make ad walls on a street to earn money.But each two of them can not be close as 5.And different ad walls can only be placed at the fixed place,and they have different values.To be honest,the length of the street is not useful.Because i just want to know how to set the walls.So the point is the walls.And it should be the only variable.So the real point should be the variable.
Have fun coding,i_human.Have fun coding,everyone!
THE CODE:
// 广告牌树立问题.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#define a 100
using namespace std;
int get(int j);
int b[2][a];
int c[a];
int d[a];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
d[i]=-1;
for(int i=1;i<=n;i++)
c[i]=-1;
for(int i=1;i<=n;i++)
{
cin>>b[0][i]>>b[1][i];
for(int j=1;j<=i;j++)
{
if(b[0][j]+5<b[0][i])
c[i]=j;
}
if(c[i]==-1)
c[i]=0;
}
cout<<get(n)<<endl;
system("pause");
return 0;
}
int get(int n)
{
if(d[n]!=-1)
return d[n];
if(c[n]==0)
return b[1][n];
if(get(n-1)>=get(c[n])+b[1][n])
{
d[n]=get(n-1);
return d[n];
}
if(get(n-1)<get(c[n])+b[1][n])
{
d[n]=get(c[n])+b[1][n];
return d[n];
}
}