there is a matrix with apple(one apple only) placed in it at some points.source and destination points are given.We have to find a path starting from source to destination which has maximum number of apples.
What should be the approach or algorithm to solve it
You can solve it by using dynamic programming .
create 2-D array where DP[i][j] finds maximum apples you can get from (0,0) to (i,j) .
Now , suppose you are travelling in right or down direction , so from (i,j) you can move to (i+1,j) or (i,j+1) .
recurrence relation : dp[i][j] = max(dp[i-1][j] , dp[i][j-1]) [for i,j = 1 to n-1].
you need to track base conditions also when i=0 or j=0.
finally dp[n-1][n-1] gives maximum apples .
Time complexity : O(n*n) as well as space complexity .
But we can optimize for space as we need to only look for previous row (i-1) for current row : i . So, space can be brought down to O(n) .
Hope it helps you !
Related
I try to understand how to input material properties using engineering constants for VTI material ( vertical transverse isotropic) with direction 3 being vertical direction. Does anyone has inp example showing how to input these material properties? For example, I don't know how to input nu12, n13? Thanks
enter image description here
As for transversely isotropic materials you have to provide 5 different parameters (I don't know what the vertical means, I never read this before).
For the convention on the poissons number please see Abaqus online documentation - conventions.
For your example. You should usually have one "master" direction (englisch is not my first language). And you have a plane perpendicular to this which has rotational symmetry. If your 3-direction is this (maybe the direction in which fibers are oriented) then your E11 and E22 values should be identical. Furthermore two of your possion numbers in your case 31 and 32 (prependicular/parallel sometimes called). Also the same directions of shear modules have to be identical.
The last shear modulus can be obtain via
G = E/2(1+nu) where E must be prependicular E modulus (2,1) and the poisson number must be the prependicular one (21)
Your constants: E33, E22=E11, nu31=nu32, nu12, G31=G32 , calculate G21 from above equation
For clarification
from H. Schürmann - Konstruieren mit Faser-Kunststoff-Verbunden (construction with fiber reinforced materials)
NOTE: In this picture the 1 direction is the parallel direction where fibers are oriented, adjust it accordingly or follow what i wrote above.
According to JPEG2000 specs, Number of tiles in X and Y directions is calculated by following formula:
numXtiles = (Xsiz − XTOsiz)/ XTsiz
&
numYtiles = (Ysiz − YTOsiz)/ YTsiz
But it is not mentioned about the range of numXtiles or numYtiles.
Can we have numXtiles=0 while numYtiles=250 (or any other value) ?
In short, no. You will always need at least one row and one column of tiles to place your image in the canvas.
In particular, the SIZ marker of the JPEG 2000 stream syntax does not directly define the number of tiles, but rather the size of each tile. Since the tile width and height are defined to be larger than 0 (see page 453 of "JPEG 2000 Image compression fundamentals, standards and practice", by David Taubman and Michael Marcellin), you will always have at least one tile.
That said, depending on the particular implementation that you are using, there may be a parameter numXtiles that you can set to 0 without crashing your program. In that case, the parameter is most likely being ignored or interpreted differently.
SCENARIO
I am working on an application that keeps track of blood glucose levels into a graph. On the graph there are "markings" (ex: -200mg) going in vertical order along the y axis on the right side of the screen and "hours" (ex: -12:00 PM) will be along the x axis on the bottom of the graph. I have to plot out little 'dots' to display what the blood glucose level was throughout the way.
ISSUE
I am trying to calculate how to position the 'dots' in the correct time and mg level and I'm having difficulty calculating the positions. I can access the "markings" and retrieve it's marking.center.x to indicate which 'Time Slot' (x axis) and the marking.center.y to indicate which 'MG Level' the 'dot' needs to go into. Problem is it isn't always exactly 12:00 PM or 200mg where it will need to be placed. In fact that would be very rare.
WHAT I NEED
Based on the following variables:
dot.mgLevel
The dot will already know where it needs to go based on the information retrieved from the medical device. It will know the time and mgLevel to assign itself.
marking.mgLevel
The markings will each have evenly distributed values that such as -100mg, -200mg, -300mg ect...
timemarking.timeslot
Each time marking on the bottom will each have evenly distributed times allocated every 30 min. Such as -12:00PM, -12:30PM, -1:00PM ect...
If the dot has a mg Level of 330mg and the closest marking on the mg Level is 300mg, then I need to be able to calculate how much further up the dot needs to move from 300 going towards the 400mg marker.
SO...
If the distance between the markings are 100pt and the dot's mgLevel is 330mg, then I know that I need to move the dot from the 300mg marking toward the 400mg marking by exactly 30pt. That's because it's simple math because the distance between the markings is 100. But in real life it isn't 100, so I need to be able to calculate this.
MY ULTIMATE QUESTION
Say distance between markings is 241 and each marking represents multiples of a hundred. Say my dot has a mgLevel of 412. How do I calculate how far I need to move the dot so that it will be in the correct place?
I THINK?
I think I need to make 241 equal 100%. But I need help.
Distance between markings is 241pt
Markings are multiples of 100mg
1mg will occupy 2.41pt. So 412mg will occupy (2.41 * 412) pt. To know how much to move for the next dot, take the difference in mg and multiply by 2.41.
In general, if distance between 2 markings in points is d, markings are multiples of m, and desired accuracy is k decimal places, 1mg will occupy g:
let divisor = pow(10.0, Double(k))
let g = round((d/m)*divisor) / divisor
Finding the shortest path between 2 points namely S and G? It SHOULD pass through points named #. The allowed pathway is denoted as . and the blocked pathway is denoted as #. The upper cap of the number of points inbetween is 19.
Example:
input
########
##....G#
##.#####
#..#..S#
##.....#
########
"It should pass through points named #" - If you can elaborate more on this. OR for the example above, what is the expected solution.
Also statement says "blocked pathway is denoted as X" and in example, we see "#". I believe you meant # as X.
I assume direction of movement would be left, right, up and down.
This can be solved by breadth first search (BFS) on the grid.
Start from S and explore all paths level by level based on given constraint where you can reach and where you can't reach.
We can take two arrays or lists say currentLevel and nextLevel. And a variable, say levelCount.
Store position S in currentLevel.
Loop through positions in currentLevel one by one. If it is G, levelCount is the shortest path.
Else, for all safe positions (left, right, up and down) where we can reach and store them in
nextLevel. "safe position" means that it should not be X, should not go beyond the given
grid extent (i.e. position index should not less than zero and not greater than length)
or other constraint given in problem.
Set currentLevel to nextLevel, increment levelCount and clear nextLevel. Go to step 1.
Hi am developing jigsaw puzzle for iPhone.
Here i have almost completed the app except finding whether the jigsaw is complete.
Here each piece is a UIImageView, and it has unique tags.
I have tried using x y coordinates, but its no use because user can start fix the puzzle from anywhere in the screen.
So, any idea how to detect whether the images are arranged correctly?
Edit: Thanks a lot all finally i have done it using co ordinates. by tracing location and tags.
Presumably, you have some sort of 'snap to grid' mechanism to put each piece precisely into the correct position once it's close (as would effectively occur with a real jigsaw). Let's say that this is defined as a specific x,y co-ordinate for the origin of the UIImageView for each piece.
Then, when each piece is in it's correct position (snapped to it's position), set a boolean 'inPlace' for that piece to YES.
When the value for 'inPlace' for all pieces is YES, the jigsaw is complete.
Check out my question here: Check how close UILabels are to each other
It is the same, except I am asking about labels, but you can try to use that with images. I am pretty sure there is a different translation scheme however
I have tried using x y coordinates, but its no use because the user can start fixing it from anywhere in the screen.
You have to select one "base" jigsaw, and get relative coordinates against it for others. Completion check - every piece keeps stored relative position equal to current. Seems, thats all.
Another case if you want to fix puzzle starting random piece and gather by parts (like torn apart image or letter - pieces have different shapes). In this case, for each jigsaw you have to store closest neighbors ids and theirs relative position. If two neighbor pieces are in place - join them. Condition to win - all neighbors for all pieces are in relative place.
What about labeling the pieces with id's
Each piece has something like
JigsawPiece.Id = 1
and label them like this (for a 3x3 puzzle);
-------------
| 0 | 1 | 2 |
-------------
| 3 | 4 | 5 |
-------------
| 6 | 7 | |
-------------
Add these pieces in a 2D array
class JigsawPuzzle:
array[3][3] JigsawPiece;
And finally check if the solution is reached by looking if the numbers are increasing by one.
check_id == 1
for int i = 0; i<numrows ; i++
for int j = 0; j<numcols; j++{
if i==numrows - 1 and j==numcols-1: break #last one, which should be empty, skip it
solved = jigsawpieces[col][row].id == check_id
check_id += 1
if !solved: break;
}
if solved: You solved it!
All is pseudo code because I don't know ObjC
Something along these lines should do the trick!