0/1 Knapsack in bottom up approach

I’ve tried the Recursive, Memoization and DP-Top-Down approach of Knapsack problem. But not able to restructure the code for DP-Bottom-Up approach. Below is my code, its only working for fewer inputs.

def knapsackBFBottomUp(W, val, wt):     n = len(val)     dp = [[0 for i in range(W+1)] for i in range(n+1)]      for i in range(n-1, -1, -1):         for j in range(W-1, -1, -1):             if j > wt[i]:                 ans = dp[i+1][j]             else:                 ans1 = val[i] + dp[i+1][j+wt[i]]                 ans2 = dp[i+1][j]                 ans = max(ans1, ans2)             dp[i][j] = ans     return dp[0][0]   n = int(input()) W = int(input()) val = list(int(i) for i in input().strip().split(' ')) wt = list(int(i) for i in input().strip().split(' ')) print(knapsackBFBottomUp(W, val, wt))  Input Which I've used. 3 2 20 30 40 1 1 1  Returns Answer as 70 

Can any one please assist me what I’m missing here? I’ll be very thankful to you.

Is it a norm in android apps to only have bottom navigation only on parent activities

I have checked multiple apps, and in most of them, bottom navigation is only visible on parent activities, when i go in any inner activity bottom navigation goes away, so my question is that is there any guideline regarding this available in material design, or everyone is just following this approach without any proper guideline,

and is it a right approach to have bottom navigation only on parent activities.

and in which cases we hide navigation on child activities, if not in all.

For example, i have an item in navigation Team, when user taps on it i open Team Screen, which contains 5 items, so when user further goes into these items i disable navigation, is it the correct approach?

Does the map of Barovia extend beyond the top and bottom of the map?

I’m currently running Curse of Strahd and plan on extending the adventure beyond the end of the published material. There are a couple of areas that the party have not gone to and I do not expect they will go to before finishing the adventure, but otherwise, I don’t want us to be just going through all the same old locations again; I wanted to add some new areas and extra content.

Looking at the map of Barovia on p. 35, I can see that the left and right edges of the map are likely the edges of Barovia, since the right hand edge is labelled A, which is where the party first arrive after walking through the fog (which I take to mean that going back in that direction just leads them getting lost and spat back out into the map, as per “Mists of Ravenloft”, pp. 23-24), and the left hand edge is likely more of this fog, given the description in Chapter 14: Yester Hill (p. 200):

This is the reasoning I’m using to conclude that the left and right edges of the map really are the edges of Barovia itself, and that there is nothing further in either direction (although, if I’m wrong about this conclusion, I’ll happily be challenged on that in an answer).

My question, however, is about the top and bottom edges of the map. At the top of the map is Mount Baratok and the various locations marked M. The bottom of the map is Mount Ghakis and a road that leads south from Amber Temple (although this could just lead off the edge of Barovia like A and road that leads west from Krezk, but it could be a road to somewhere else in Barovia). There’s nothing written in this adventure that implies that these are the edges of Barovia itself (yes, there’s the “fog effect” around the edges of the map, but I assume that’s just for style, since otherwise Barovia is a neat rectangle shape – unlikely).

Of course, I as the DM could just decide that these aren’t the edges of Barovia as that suits my purposes, and if it turns out that these are actually edges of Barovia, that’s likely what I’ll do, but I wanted to know if there was anything published about Barovia (likely from older editions of D&D, but if there is anything I’ve missed in 5e, I’d prefer that) that describe what might be beyond the edges of the map. Are there any maps in previous editions that roughly match up with the map I’m using that shows anything further north and south, or anything I’ve missed in 5e Curse of Strahd?

How to determine valid handle for given bottom up parser?

I came across following question:

Consider the grammar:

$ E → E + n\text{ | }E × n\text{ | }n$

For a sentence n + n × n, the handles in the right-sentential form of the reduction are
(A) $ n, E + n$ and $ E + n × n$
(B) $ n, E + n$ and $ E + E × n$
(C) $ n, n + n$ and $ n + n × n$
(D) $ n, E + n$ and $ E × n$

Solution given was:

n+n×n    E+n×n  //reduce n to E E×n    //reduce E+n to E E      //reduce E×n to E 

Hence option D

Then I came across following problem:

Consider the following grammar:
$ A\rightarrow A(B)|B$
$ B\rightarrow B*C | id $
$ C\rightarrow (id)$
Which of the following can be the correct handle in bottom up parsing for the given grammar? (A) (id)
(B) id*C
(C) id
(D) none

The given solution was (A)(id)


  1. After thinking about the definition of the handle and two problems, I concluded following:

    • If problem asks which are valid handles for given string and grammar, then we have to actually try parsing that string with given grammar and determine which handles are reduced during parsing.

    • But, if no string is given, and just the grammar is given, then following are valid handles:
      (a) right hand side of each production
      (b) those sentential forms which can be derived from start symbol by doing rightmost derivation are valid handles. For example, $ B*(id)$ is a valid handle as we can derive it by doing rightmost derivation as follows: $ S\rightarrow B\rightarrow B*C\rightarrow B*(id)$

  2. As explained in 2nd bullet point of point 1 above, answer of 2nd problem is wrong and both of $ A$ and $ C$ options are correct: both $ (id)$ and $ id$ are valid handles.

Am I correct with both conclusions above?

Calcluate Mesh top, bottom, left and right position relative to mouse click position on the mesh

I have a mesh (suppose it can be circle, or rectangular,square or an arc). The geometry of the mesh can be anything. I can click on mesh at any position. From relative to the clicked position, I want to get its right, left top and bottom position of the mesh. Maybe the picture explain it better then my words enter image description here

bottom sheet dialog or complete screen for new task

I am developing something similar to task app. For new task screen there is two approaches to go with

  • Bottom sheet dialog like in Google Tasks, Todoist
  • Complete screen with items laid out vertically.

In Todoist, it have natural language understanding capabilities and support both of this approaches, while giving priority to bottom sheet app. Google Tasks app only support bottom sheet approach for new tasks.

The thing I cannot understand is Why give priority to bottom sheet approach? What so user friendly about it? If you see Todoist new task screen, buttons are small and tightly packed, yes it have natural language understanding capabilities, so you could type things in text.

New approaches with better UX for new task screen are also welcome!

Como puedo colocar objetos top y bottom en android?

Hola quiero poner un fragment debajo de un objeto y el margiBottom que lo haga hasta otro boton pero si pongo el codigo del layout_marginBottom se cierra la app

el frameLayout esta dentro de un relative

<FrameLayout         android:id="@+id/contenedorFragments"         android:layout_width="match_parent"         android:layout_height="660dp"         android:layout_below="@id/settings"  //sin la ultima linea funciona           android:layout_marginBottom="@+id/onair"/> con esta linea ya se cierra la app 

How to push items to the top or bottom of the list in alphabetically sorted lists?

This question is not related to any specific scenario, platform or product, and it’s more of an end-user UX rather than a design of UX. It applies to various use cases and platforms. One specific example which prompted me to ask this question is the notebooks list in Evernote – I’d like to push my notebook called “Archives” to the bottom of the list – it’s right at the top otherwise. Another cases are naming the files and folders on a computer.

There are certain lists which are sorted alphabetically and there’s no way to re-arrange them. In general, this is quite practical as it makes it easier to find the items when there are plenty of them and there’s no need to arrange them manually.

However, sometimes you want to push certain items on the list to the top or to the bottom. And the only way to do that is to prefix the item with a certain symbol.


  • For pulling items to the top, the most common I’ve used is !, so your Requirements item becomes ! Requirements. Other nice options are ~ or -.
  • For pushing to the bottom however, one obvious symbol is “z”, so if the item is named Archives, you name it zzz-Archives or zzz Archives.

While the exclamation mark and other non-alpha symbols seem OK, I find zzz knocks off the visual “tidiness” of a list.

I am wondering if anyone used or seen more elegant solutions to pushing and pulling?