Bzoj 4145 [AMPPZ2014] The Prices Problem solving report

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.