Keywords: logic, pirate, gold
(This post is adapted from ianstewart's fierce pirate logic in the Scientific American magazine.)
You have heard of the pirates. This is a group of desperate people who snatch money at sea and seize their lives. What they are doing is licking blood on the head of a knife. In our impressions, they usually blind one eye and use a black cloth or a black eye mask to cover the bad eyes. They also have a good habit of burying treasures in the ground, and always draw a tre
Questions like this:
There are eight coins, one of which is fake, and the amount is measured on the balance. I don't know whether the fake is really heavy or light. Could you tell me how many times it will take to determine whether it is false, severity (5 points ). Use C code (25 points ).
First, determine the number of times
8 balls * 2 status = 16Balance 3 (left and right)Known 3 ^ 2 So it can be called at least three times.
Then, find out the ba
I find it?The "state" is used to describe the solution of the problem's sub-problem. There are two paragraphs in the original that are not very clear, skip the direct example.If we have several coins of $1, $3 and $5, how can we make up to $11 with the fewest coins? (The surface of this problem can be greedy algorithm, but greedy algorithm can not guarantee that the solution, such as 1 yuan to 2 yuan when)
Coin change time limit: +Ms | Memory Limit:65535KB Difficulty:3
Describe
In real life, we often encounter coin change problems, for example, in the payroll, the financial personnel need to take into account
Count The minimum number of change coins so that they can get the minimum number of coins from the bank and make sure they can pay with these
describe it?Dynamic programming algorithms are usually based on a recursive formula and one or more initial states. The solution of the current sub-problem is introduced by the solution of the last sub-problem. The use of dynamic programming to solve problems requires only polynomial time complexity, so it is much faster than backtracking, violence and so on.Now let's take a look at the fundamentals of DP in an example.First, we need to find the optimal solution of a state and then, with its he
based on a recursive formula and one or more initial states. The solution of the current sub-problem is introduced by the solution of the last sub-problem. The use of dynamic programming to solve problems requires only polynomial time complexity, so it is much faster than backtracking, violence and so on.Now let's take a look at the fundamentals of DP in an example.First, we need to find the optimal solution of a state and then, with its help, find the optimal solution for the next state.What d
only polynomial time complexity, so it is much faster than backtracking, violence and so on.Now let's take a look at the fundamentals of DP in an example.First, we need to find the optimal solution of a state and then, with its help, find the optimal solution for the next state.what does "status" mean and how do I find it?The "state" is used to describe the solution of the problem's sub-problem. There are two paragraphs in the original that are not very clear, skip the direct example.If we have
it?Dynamic programming algorithms are usually based on a recursive formula and one or more initial states. The solution of the current sub-problem is introduced by the solution of the last sub-problem. The use of dynamic programming to solve problems requires only polynomial time complexity, so it is much faster than backtracking, violence and so on.Now let's take a look at the fundamentals of DP in an example.First, we need to find the optimal solution of a state and then, with its help, find
B is 2.Your task is to compile the fastest program to calculate the editing distance of any two strings.
Input data:1th behavior string A; 2nd behavior string B. Note: The length of the string is not greater than 1000, and the character Embox in the string is uppercase.
Output data:Edit the distance.Analysis
Dp
f[i][j]The minimum editing distance that represents the first I character of A and the first J character of B
Initializationf[i][0] = i//means to delete all t
Researchers have long discovered that the dirtiest thing in the world is not excrement, sludge, but coins, especially paper money.The truth about germs on coinsA few years ago, a study by the City University of Hong Kong showed that in Hong Kong, China, India, Pakistan, Cambodia, the Philippines, North Korea, 7 Asian countries and regions of the currency, the renminbi banknotes of the most bacteria, the number of 178,000, more than the second Hong Kon
[Description]
John is playing a simple computer game.
There is a circular road in the game. There are n robot factories on the road, and two adjacent robot factories are connected by a short road. Starting from a robot factory, Xiao Xin sequentially numbered the N robot factories as 1 ~ N, because the road is circular, the N robot factory and the 1st robot factory are connected by a section of the road. John will connect the N roads in the robot factory to 1 ~ N, and specify section I to con
Many people blindly draw gold coins from taojianghu. As a result, many gold coins were used, but nothing was obtained. Think gold coins only
It depends on luck. In fact, this is still skillful and regular. The following is a summary of how to open an online shop and how to make a lucky draw for gold coins.
Tips,
need to find the optimal solution for a certain state, and then find the optimal solution for the next state with its help.
What does "status" mean and how to find it?
The "status" is used to describe the subproblem of the problem. There are two paragraphs in the original text that the author does not know clearly. Skip the example above.
If we have several coins with a nominal value of 1 yuan, 3 yuan, and 5 yuan, how can we use a minimum coin to mak
Title DescriptionXiao Xin is playing a simple computer game.In the game there is a roundabout road, there are N robot factories on the road, and two adjacent robot factories are connected by a small section of the road. Small new start with a robot factory, in the clockwise order of the N robot factory numbered 1~n, because the road is annular, so the Nth robot factory and the 1th robot Factory is connected by a section of the road. Small new will be connected to the robot factory, the N-section
a game of two people facing several piles of coins (or stones). There are k>=1 piles of coins, each containing n1,n2, ... NK Coin. The goal of the game is to choose the last remaining coins. The rules of the game are as follows: 1. Two game players alternately play (Game man I and Game Man II); 2. When it is time for each player to take the time, select a bunch
nature of a Nim situation in O (n) time. If it is N-position, it can also be in O (n) find all winning strategies in time. The Nim problem is basically perfectly solved.
(From Baidu encyclopedia)
Nim game image details:Nim play is a game where two people face several coins (or stones. With k> = 1 heap of coins, each heap contains N1, N2 ,...... NK coins. The goa
A case study of dynamic programming
If we have a number of coins with a nominal value of 1 yuan, 3 yuan and 5 yuan, how can we use the least coins to gather up 11 dollars? (On the surface of this problem can use greedy algorithm, but the greedy algorithm can not guarantee to find solutions, such as 1 yuan to 2 yuan when)
First we think about a problem, how to use the smallest
Combined mathematics-nim sub-gameNim play is a game where two people face several coins (or stones. With K> = 1 heap of coins, each heap contains N1, N2 ,...... NK coins. The goal of the game is to choose the last remaining coin. The rules of the game are as follows: 1. two gamers play the game in turn (game player I and game player II); 2. when it is the turn of
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.