Monotonous queue - Games

· Today exams! ! However, goose burst! !

 

· Title Contents :

1 .Background
CZR Although a college student, but he still likes to sneak play hopscotch at home .
2. the Description
CZR family has a continuous N + 1 piece of land tiles, numbered from 0 to N , he was on every piece of tile
are written on one number .
he started at 0 No. floor tiles, floor tiles this score is 0 , he will jump back each time step,
but he does not need to jump to the last .
because of his ability to not jump, so he can only go step after the jump L to R grid, that is to say
the tiles i , he can only jump tiles i + L to i + R is a brick .
he carried a fraction of the sum of the game is to score all his jumps tiles sum .
now he wants to get the most points, to prove their mathematical ability is very strong, so he needs
to know the maximum score is how much .

· Topic Source : Shandong Jinan training exams two second title

· Topic ideas :

So that F [i] denotes the i lattice CZR jump when he can get the maximum score.
The F [i] = max (F [i - L] ... F [i - R]) + a [i]. (a [i] represents the fraction of point i)

We want to optimize the max (F [i - L] ... F [i - R]).
This was taken over i is 1-n.
Simply means that a required interval maximum value, the interval length is fixed.

There are many ways you can do:
One of the most simple way is monotonous queue
seeking the maximum interval, the interval is fixed, which is obviously simple optimization problem monotonous queue.
And queue monotony is also very good writing, divided into the team and the team two steps alone.
monotonically queue time complexity is O (n) a.

And then magnify that problem, can become:
Asking a maximum number of columns in the interval, the interval length is not fixed
, because without modification, just ask, so this is obviously a st table
transfer time to a query on the table st well.
time complexity is O (nlogn + n).

Of course not st table can still do
we then magnify that problem:
a set of three operations:
adding a number; delete a number; the current maximum number of request within the collection.
For only join a number within the current collection request + the maximum number of a stack is complete.
to delete a number you can then create a number of heap memory to be deleted.
every time the query to see elements of both top of the heap heap enough.
the time complexity of O (nlogn).

· Board :





	
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

 

Guess you like

Origin www.cnblogs.com/konglingyi/p/11391081.html
Recommended