The feeling is also a small fresh question.
We considered setting the status $Dp [I][s]$ said that after considering the previous $i $ store, the purchase status was the minimum cost of $s $.
If you move, enumerate each store $i $, and first make:
$ $Dp [I][s] = Dp[i-1][s] + d[i]$$
This process means arriving at the store.
Then enumerate each state $s $, and then enumerate each item that is not in the $s $ $j $, so that:
$ $Dp [I][s + \{j\}] = min (Dp[i][s + \{j\}], Dp[i][s] + cost[i][j]) $$
This process is equivalent to a 01 backpack.
Finally make $Dp [i][s] = min (Dp[i][s], Dp[i-1][s]) $ to see if the purchase plan is cost-effective at the store $i $.
The Complete collection is $S $, so the final answer is $Dp [n][s]$.
Time complexity $O (nm2^m) $, spatial complexity $O (N2^M) $.
1#include <cstdio>2 #defineMin (A, B) ((a) < (b)? (a): (b))3 #defineN 100 + 54 #defineM 16 + 55 #defineSIZE 1 << 166 #defineINF 5931196817 8 intN, M, W[n], map[n][m], dp[n][size];9 Ten intMain () One { Ascanf"%d%d", &n, &m); - for(inti =1; I <= N; i + +) - { thescanf"%d", W +i); - for(intj =1; J <= M; J + +) -scanf"%d", Map[i] +j); - } + for(ints =0; S < (1<< m); S + +) -dp[0][s] =INF; +dp[0][0] =0; A for(inti =1; I <= N; i + +) at { - for(ints =0; S < (1<< m); S + +) -Dp[i][s] = dp[i-1][s] +W[i]; - for(intj =1; J <= M; J + +) - for(ints =0; S < (1<< m); S + +) - if((S & (1<< J-1)) ==0) inDp[i][s ^ (1<< J-1)] = min (dp[i][s ^ (1<< J-1)], Dp[i][s] +map[i][j]); - for(ints =0; S < (1<< m); S + +) toDp[i][s] = min (Dp[i][s], dp[i-1][s]); + } -printf"%d\n", dp[n][(1<< m)-1]); the * return 0; $}4145_gromah
Bzoj 4145 [AMPPZ2014] The Prices Problem solving report