(1) Numbersolitaire
A game starts with a row of n squares, with a lattice number 0. N-1, at first, the pieces in a[0], each lattice has an integer (possibly positive, possibly negative). You are in lattice I, you throw the dice, get the points x = [1..6], and then go to the lattice numbered i + x, if this lattice does not exist, throw a dice again until i + x lattice exists. When you go to the N-1th grid, the game is over. The number of integers you pass through the lattice is your score, and the maximum possible score?
Data range: N [2..10^5], the range of the number of squares [-10000, +10000].
Complexity of requirements: Time O (n), space O (n)
Analysis: An obvious dp dp[i] = a[i] + max (Dp[i-x]) 1<=x<=min (6,i)
Code:
You can use includes, for example://#include <algorithm>//you can write to stdout for debugging purposes, e.g./ /cout << "This was a debug message" << Endl;int solution (vector<int> &a) { //write your code in C++11 const int inf = 2000000000; int n = a.size (); Vector<int> DP (n); Dp[0] = a[0]; for (int i = 1; i < n; ++i) { dp[i] =-inf; for (int j = min (6, I); j;--j) { dp[i] = max (Dp[i], dp[i-j]); } Dp[i] + = A[i]; } return dp[n-1];}
(2) Minabssum
http://blog.csdn.net/caopengcs/article/details/10028269
Exercises on codility (15)