Luogu P3694 Bang Bang Queued "pressure dp" by cellur925

Source: Internet
Author: User

Topic Portal

When I first learned to stress ... The seniors are talking about the problem. It seemed to me that I was listening to the heavenly book when I just seemed to understand the non-aggression and the artillery position. Because I thought at that time, this is not what chess board, how like pressure ah?! Later found this kind of pressure more to go to the HHH. Later this problem has been pressed, and now the pressure to understand a little to pits.

We note that the number of team members is $n$ and the number of groups $m$ is small (not called a band). Then we can work on the $m$ and press it into a binary string. The first thought was that 0 said the group was not standing still, and 1 said the group was standing by. look at Jtdalao's article found that his state is right, but the transfer of ..., a bit of a feeling. Step-by-step. First of all we must enumerate what the current state is, according to the pattern of pressure DP, we will next enumerate the next time the new station is a good team. We need to use the number of times that the new team is standing up and the number of people we need to stand in the new team. We're all lined up in one column, so we need to find out who we are now. So we also need to open an array prefix and to record the queued information. Set the number of $sum[i][j]$ to the $i$ location, $j $ group.

Transfers are:

$f [i]$= $min $$ ($f [i^ (1<<j)]$+ $num [j]$-($sum [pos][j]$-$sum [pos-num[j]][j]$]).

Because there may be members of the team before the new addition, subtract them.

Initial value, because the smallest, so began to be large, $f [0]=0$. Boundary

After that it was better to think about = =.

$Code $

1#include <cstdio>2#include <algorithm>3#include <cstring>4 5 using namespacestd;6 7 intN,m,fake;8 intf[1<< at],num[ -],sum[100090][ -];9 Ten intMain () One { Ascanf"%d%d",&n,&m); -      for(intI=1; i<=n;i++) -     { the         intx=0; -scanf"%d",&x); -num[x-1]++; -sum[i][x-1]++; +          for(intj=0; j<m;j++) -sum[i][j]+=sum[i-1][j]; +     } AFake= (1&LT;&LT;M)-1; atMemset (F,0x3f,sizeof(f)); -f[0]=0; -      for(intI=0; i<=fake;i++) -     { -         intpos=0; -          for(intj=0; j<m;j++) in             if(i& (1&LT;&LT;J)) pos+=Num[j]; -          for(intj=0; j<m;j++) toF[i]=min (f[i],f[i^ (1&LT;&LT;J)]+num[j]-(sum[pos][j]-sum[pos-Num[j]] [j])); +     } -printf"%d\n", F[fake]); the     return 0; *}
View Code

Luogu P3694 Bang Bang Queued "pressure dp" by cellur925

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.