## Knapsack with a fixed number of weights

Consider a special case of the knapsack problem in which all weights are integers, and the number of different weights is fixed. For example, the weight of every item is either 1k or 2k or 4k. There is one unit of each item.

The problem can be solved using dynamic programming. Suppose the knapsack capacity is $$C$$, and the most valuable item of weight $$w$$ has a value of $$v_w$$. Then, the maximum value of KNAPSACK($$C$$) is the maximum of the following three values:

KNAPSACK($$v_1$$,$$C-1$$), KNAPSACK($$v_2$$,$$C-2$$), KNAPSACK($$v_4$$,$$C-4$$).

Is there a more efficient algorithm? Particularly, is there a greedy algorithm for this problem?

I tried two greedy algorithms, but they fail already for weights 1 and 2. For example, suppose there are 3 items, with values 100, 99, 51 and weights 2, 1, 1:

• If the capacity is 2, then the greedy algorithm that selects items by their value fails (it selects the 100 while the maximum is 99+51).
• If the capacity is 3, then the greedy algorithm that selects items by their value/weight ratio fails (it selects the 99+51 while the maximum is 100+99).

However, this does not rule out the possibility that another greedy algorithm (sorting by some other criterion) can work. Is there a greedy algorithm for this problem? Alternatively, is there a proof that such an algorithm does not exist?

## How i can perform most damage and mobility within this fixed classes?

My character is Air Genasi (+2 dex, -2 cha)

Classes: Fighter 2/Shadowcaster 1/Scout 1/Ardent 1;

He have next stats: STR 10 DEX 20 CON 14 INT 14 WIS 11 CHA 9

Feats: Point Blank Shot(PHB), Willing Deformity, Willing Deformity(Teeth), Weapon Finnesse

He nibbled off his hand, so he is totally one-handed and use rapier now, and off-hand 1d4 bite attack from willing deformity.

As shadowcaster (ToM book) he have a next spells: -arrow of dusk (2d4 nontlethal ray) -caul of shadow (+1 to AC deflection bonus) -steel shadows (+6 to AC)

Class was taken mostly for flavor in case of characters extraplanar heritage.

As ardent (CP book) he have next options: mantles: Freedom, Pain and Suffering; and power Dimension Hop which allows to 10 ft. move as swift action. +5 ft. for investing power points

As scout (CA book) he have a Skirmish ability (+1d6 to damage of all attacks during the round where character was moving at least 10 ft… +2d6 at 5-th lvl and so on, scalable damage)

Basic style is – 1. Dimension hop to enemy, and it triggers skirmish (because to trigger you must move, dimension hop description says that you instantly move, not teleproting, transfering or other) 2. Full attack with rapier and bite (1d6+1d6, 1d4+1d6) with +7(rap)/+2(bite) attack modifiers.

+5 dexterity bonus, and Steel Shadows help me to keep high AC. Also my character good at intimidation, stealth move and hiding. Potentially i can reach hustle (from Freedom mantle) and Flicker (from Shadowcaster class), to keep me mobile

I’m also thinking about Arcane Strike feat, but not sure.

So, questions is – what i can do, to improve basic style? Maybe there is can be some another combos, much devastating? In what class from the Ardent\Scout\Shadowcaster triad is better to progress first? second?

Books of D&D 3.5:

Player’s Handbook (PHB) Tome of Magic (ToM) Complete Adventurer (CA) Complete Psionic (CP) Expanded Psionic (EP)

## How to design a chart that has an x-axis with a fixed range that is longer than the selected range?

I’m designing a web-based analytics dashboard that contains a chart in which the x-axis represents the days of a campaign, and it always shows 31 days. However, the duration of a campaign varies; it may be predefined to any period between a single to 31 days.
In cases when the campaign’s duration is shorter than 31 days, I want to make it clear which area of the chart is relevant.
Are there any existing best practice solutions for this scenario?
One idea I have is graying out the area that’s not required (see image below).

The chart’s width is fixed and optimized for displaying a 31-days range. I’m not changing the number of days on the x-axis to avoid scenarios in which there is a single floating dot or bar on the screen or several data points with vast space between them (see images below).

## Allow a fixed Two rows to display product title

Hi,

Please, How to make the product titles AUTOMATICALLY displayed in Woocommerce archive (home & categories) on TWO lines (around 10 words).

The site is not live yet.

I join two pdf files of the Woocommerce archive (before and after). The after one is a photo editing to illustrate.

If you can see I expect:

* To set a permanent and fixed two lines' space for the products' title.
* If the title exceeds Two lines, the 'read more' should be displayed like this: (…)
* Although…

Allow a fixed Two rows to display product title

## Jumping to anchor within modal with a fixed header

Hi all,
I am having a bit of a problem.
I have a script that is for nested modals, that when a link is clicked it jumps straight to an anchor. It works fine.
However when styling, I would like to have a fixed header as the ".content" div scrolls to the anchor.
When ".content" has a height of 80vh it looks fine, but the script doesn't scroll to the anchor.
When ".content" has a height of 80% the script works, but the fixed header doesn't stay fixed and scrolls with the ".content".
How can I…

Jumping to anchor within modal with a fixed header

## Compiz: Fixed window placement, which alternative?

At login two windows are automagically opened. For the purpose of fixed location of these, I am trying CompizConfiguration Settings Manager, function Place Windows. The Fixed Windows Placement tab gives me three choices: Windows with fixed position, Windows with fixed placement mode, and Windows with fixed viewport.

What is the difference between these alternatives? I have tried to find an explanation, but miserably failed. Any light on the matter is gratefully received.

## Sampling a uniform distribution of fixed size strings containing no forbidden substrings

Given a list of “forbidden” words (substrings), an alphabet, and a desired output string length, how would I efficiently sample output strings containing no forbidden word?

For short output strings with few forbidden words, I would use simple rejection sampling. Pick a string (uniformly) with the specified alphabet and length, return that string if it contains no element of the forbidden list, try again otherwise.

If I use that algorithm for output lengths several times larger than the typical forbidden word, then the probability of rejection will be higher. (Most words are 2 or 3 characters long.)

Assume the requested output length is too long to enumerate and store every possible value. My alphabet size would be 16 to 36 characters, but solutions to large alphabets would be interesting to think about. (In which case I would call these things random sentences, forbidden n-grams, and dictionary words.)

My forbidden word list will have one hundred to one thousand strings. I would like to avoid solutions requiring expensive precomputation or lots of memory.

My first idea was to try to build a random string incrementally, in contrast to the all-or-nothing approach of straightforward rejection sampling. I doubt that my algorithm produces each possible output with equal probability.

The algorithm idea follows:

1. Initialize a char buffer long enough to fit `outlen` characters.
2. Pick a random letter of the alphabet and append it to the buffer.
3. If the buffer ends with a forbidden word of length `k`, then remove the last `k` letters from the char buffer and go to 2.
4. Otherwise, go to 2 if the buffer has less than `outlen` characters.
5. Return the contents of the buffer if it is full.

Step 3 serves to rewind the algorithm, returning the char buffer to a previous legal state.

I understand that clearing the whole buffer in step 3 definitely would produce uniform output just like the straightforward rejection sampling method. However, the average number of rejections before the first valid output is generated will be the same.

I’ve gotten stuck trying to determine if my proposed algorithm is uniform. I have had no luck finding alternative algorithms either. I haven’t yet looked at how this algorithm’s performance would compare to basic rejection sampling.

## What causes the over-the-air TV channels to go blank when someone starts using the internet on the home computer? How can it be fixed? [on hold]

What causes the over-the-air TV channels to go blank when someone starts using the internet on the home computer?  How can it be fixed?

## Using a fixed decimal when filling a currency amount input field

When entering currency amounts into an input field, I’ve seen two methods:

Keyed Decimal: The keypad includes the decimal character and the user enters the decimal along with the numbers. The Chase mobile app uses this approach.

``Key  Display  5       \$  5  4      \$  54  .     \$  54.  6    \$  54.6  3   \$  54.63 ``

Fixed Decimal: The keypad excludes the decimal character and the numbers fill around a fixed decimal. The PayPal and Square mobile apps both use this approach.

``Key  Display  5    \$  0.05  4    \$  0.54  6    \$  5.46  3   \$  54.63 ``

The keyed decimal approach seems more straightforward to me, and it also requires 2 fewer keystrokes when entering non-decimal amounts (e.g. \$ 10 only requires typing 1-0, instead of 1-0-0-0). However, users of our payment processing app have accidentally charged amounts like \$ 123,456.00 instead of \$ 1,234.56 because they were expecting a fixed decimal interaction instead of a keyed decimal interaction.

Is this just a matter of preference, or are there other merits to a fixed decimal approach that I may be overlooking?

## set (fixed) tab titles, for different profile

Ubuntu 18.4.

In my gnome-terminal I have defined let’s say 2 profiles: hostA hostB

Profile of hostA execute custom command “ssh hostA.example.com”. Profile of hostB execute custom command “ssh hostB.example.com”.

So, when I click: file -> new tab -> hostA I connect to hostA when I click: file -> new tab -> hostB I connect to hostB

Now, when I open a new tab on profile hostA I would like ‘hostA’ to be the tab title of that terminal tab, when I open a new tab on profile hostB I would like ‘hostB’ to be the tab title of that terminal tab

Is that possible?

Thank you very much.