Simple DP, the optimal sub-structure is dp[i], that is, from 0~i, yes Dp[i] max, and then find the largest in the largest can be,The transfer equation is: dp[i]=max{dp[i],dp[j]+value[i]}, note that there are two criteria for judging.#include"iostream"#include"stdio.h"#include"string.h"#include"algorithm"#defineMX 1010using namespacestd;__int64 N;__int64 Value[mx];__int64 dp[mx];intMain () {__int64 I,j,ans; while(cin>>n,n) { for(i=1; i) Cin>>Value[i]; Memset (DP,0,sizeof(DP)); value[0]=0
PHP current loop is 1, loop from inside to outside increments, break default is 1, such as jumping out of the 2nd layer loop
for ($i =0; $i
foreach (Array () as $val) {
foreach (Array () as $val) {
echo "1-layer loop";
Break 2; Jump out of the 2nd layer loop
}
echo "2-layer loop";
}
echo "3-layer Loop";
}
Results:
1-Layer Loop
3-Layer Loop
1-Layer Loop
3-Layer L
The topic describes a frog can jump up to 1 steps at a time, can also jump on the level 2. Ask the frog to jump on an n-level step with a total number of hops.对于第n个台阶来说,只能从n-1或者n-2的台阶跳上来,所以F(n) = F(n-1) + F(n-2)斐波拉契数序列,初始条件n=1:只能一种方法n=2:两种递归一下就好了public class Solution {public int Jumpfloor (int target) {if (target return 0;else if (target = = 1)return 1;else if (target = = 2)return 2;ElseReturn Jumpfloor (target-1) + Jumpfloor (target-2);}}Fibonacci (Recursive thinking)
increment by 1. The method of updating Cur is to compare the larger values in the current cur and i + a[i], and so on when I loop to the pre value, the number of hops plus one, if the title does not indicate whether the end can be reached, we can also determine whether the pre and cur are equal, if the equality of the cur is not updated, That is, you cannot reach the end position, return-1, the code is as follows:Solution OneclassSolution { Public: intJumpintA[],intN) {intres =0, i =0, cur =
Board horse jumping Problem
The recursion problem is explained by Teacher Zhang during summer training.
On a 5*5 chessboard, the horse starts from a grid and can only jump to the grid that can be placed in the current position as a day, find all the ways to skip the 25 grids.
Example:
X1, Y1
X1, Y1
X1, Y1
X1, Y1
X, Y
X1, Y1
grew up in the high bridge, judge eg and EV size;If the rope length is less than the height of the bridge, compare the size of eg and Ek, eg 1 /*2 k rope stiffness coefficient3 L Rope Length4 the height of the S-Bridge5 W Weight6 */7#include 8 #defineG 9.819 intMain ()Ten { One Doublek,l,s,w; A DoubleEg,ek,ev; - while(SCANF ("%lf%lf%lf%lf", k,l,s,w) (k+l+s+W)) - { theeg=w*g*s; -ev= -*w/2; -ek=k* (s-l) * (s-l)/2; - if(L >=s) + { - if(Eg Ev) +printf"J
1. Title Description: Click to open the link2. Problem-Solving ideas: The use of scanning and maintenance solutions. According to test instructions, the largest convention to be able to walk to all the squares that must be the number of cards selected is 1, which is well understood. Because ax+by=1 means that if you have a x and b y, you can step up the number of steps 1. In this way, you only need to use map to store the minimum cost for all the conventions. At the beginning of the base[0]=0, t
Today I made a Web page to set up an IFRAME in the Web page, and then apply the other sites. Using http://luanqi-cat.blogbus.com This URL, there is a puzzling problem, my page actually will be forced to automatically jump to this page. Search for some, only to know the original page with the following section of code:if (top.location! = self.location) {top.location=self.location;}After using this code, it will automatically determine whether the current location is the top level, that is, whethe
button to scroll to the specified position? button buttons can not add href, only zigzag solution. First create a hidden anchor point, and then click on the button to add an onclick event, and then through the JS to invoke the anchor point click Event, the curve to salvation. type= "Button" value= "click button Jump" onclick= "click_ Scroll/> id="Anchor_scroll" href= "#pos" style="display :None"> click here to jump to ...here is a lot of text, put the page open, hang out t
The frog jumping game is a seemingly simple intelligent game. The game task is to change the positions of frogs on both sides of the game. Click the frog and it will jump to a vacant stone closest to it. Yesgame interface:
Crop + crop/crop + zcrHye62yMvRy/ejrNXStb3Su7j2veK + zU9LoaO0 + crop + CjxwcmUgY2xhc3M9 "brush: java;"> pos = [0 for x in range (7)] for I in range (3): pos [I] =-1for I in range (3): pos [6-i] = 1 # print (pos) repos = pos [:: -1]
This article describes how to implement the label jumping out loop in javascript. If you are interested, refer to the following:
First, let's talk about why label labels are needed. Although we already know that break exists and continue jumps out of the loop, if there are multiple loops, they are obviously powerless, so the label is displayed to serve us.
Let's take a look at the use of break separately.
for(var i=0;i
Running result:
I: 0 -- j: 0
Parse prototype. The method for jumping out of the each loop in JQuery
This article mainly introduces how to jump out of the each loop in prototype and JQuery. For more information, see.
The Code is as follows:
Function chk (){
Var flag = true;
Var msg = '';
Var tips = {'username': 'name', 'tel ': 'tele', 'Company': 'Company name', 'loupan _ name': 'House name ', 'sdate': 'group buying time', 'content _ 1': 'group buying content '};
$ ('. Required')
1, before the operation of the actual line with G, you can operate on the screen line, for example: ' GJ ' means to move down a screen line, ' g^ ' for moving to the screen line of the first non-whitespace characters and so on2. Vim has two sets of commands for forward and reverse movement of words:
W forward moves to the beginning of the next word
b Reverse moves to the beginning of the current word/previous Word
E forward moves to the end of the current word/previous Word
GE mov
Xiao Kee
1. About the initialization of fragmentWhen we set up the interface using the avtivity+fragment combination, we usually have new fragment in the activity, but when we need to pass the parameters in fragment, Are we going to have a problem with the way we use the constructor in the fragment? Yes, we are using the method of construction in the Androidstudio parameter, will be error, simply said: "Fragment in the way the parameter assignment can cause a memory leak problem", the code
"White-space:pre" > /Implementation Wait a few seconds after the jump, method one New Handler (). postdelayed (new Runnable () {@OverridePublic void Run () {Intent Intent = new Intent (mainactivity. This, Exampleactivity.class); StartActivity (Intent);}}, Splash_display_lenght);Implementation wait a few seconds after the jump, method twoFinal Intent localintent = new Intent (This, exampleactivity. Class); Timer timer = new timer (); TimerTask tast = new TimerTask () {@OverridePublic void Run ()
1 Service-side jump, jump immediately, subsequent statements will not be executed;2 The client jumps, redirects 301 ways, and the returned response header will have a location entry. The subsequent code will continue to execute before the jump, which is equivalent to setting the Jump action delegate to the response header.3 in servlet: RequestDispatcher view = request.getrequestdispatcher ("url");View.foward (request, response);Service-side jump, the subsequent code will continue to execute befo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.