DescriptionThere is a row of n coins whose values was some positive integers c?, C?,..., cn, not necessarily distinct. The goal is to pick up the maximum amount of money subject to the constraint that no, coins adjacent in the initial row Can is picked up.InputLines, the first line was N (0< n <=10000), and the second line is the value of coin (0< value <= 2^32).OutputThe maximum amount of money. Sample Input65 1 2 6 2Sample Output17 topic: is to give you a row of numbers, not able to take the adjacent numbers, ask the number of the largest and how much ~ ~Ideas:Can not be adjacent then consider the current bit of the first two number corresponding to the best state + current number, and the current number of the previous number of the state comparison, here the boundary dp[0]=0,dp[1]=x[1] (x data element array starting from 1 storage); Code:
#include <iostream>
using namespace Std;
int n, dp[10001], I, x[10001];
#define MAX (A, b) a>b?a:b
int main ()
{
CIN >> N;
for (i = 1; I <= n; i++)
{
CIN >> X[i];
}
DP[1] = x[1];
for (i = 2; I <= n; i++)
{
Dp[i] = max (dp[i-1], dp[i-2] + x[i]);
}
cout << dp[n] << "\ r \ n";
return 0;
}
Coin-row problem (1139)