Codevs 2451 Non-invasive (like ya DP)

Source: Internet
Author: User

/*Good magic ... I mean, there's a lot to be learned. Note that n<=9 is not a search or a search + pruning 70 points enumeration put or not put here with the shape of the AH F[i][j][k] means the first I row put J King I row state is K of the scheme number of the transfer words enumeration the state of the lower level to calculate the state there are several kings and then update complexity 2^n*2^n*n*k*n the last n is the king number this can be pre-treatment to get out there is a problem is the problem of mutual harm first in the same row adjacent to the left to move to the right to move a bit better incidentally handle two states can transfer the last σf[n][k][i]*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 520using namespacestd;intN,K,V1[MAXN],V2[MAXN][MAXN],CNT[MAXN];Long Longans,f[Ten][ -][MAXN];voidget_v () { for(intI=0;i< (1&LT;&LT;N); i++)      if((i& (i>>1))==0) {V1[i]=1;intC=0;  for(intj=i;j;j>>=1) c+=j&1; Cnt[i]=C; }     for(intI=0;i< (1<<n); i++)if(V1[i]) for(intj=0;j< (1<<n); j + +)if(V1[j])if((i&j) = =0&& (i& (j>>1))==0&& (j& (i>>1))==0) V2[i][j]=1;}intMain () {CIN>>n>>J;    Get_v ();  for(intI=0;i< (1&LT;&LT;N); i++) f[1][cnt[i]][i]=1;  for(intI=2; i<=n;i++)       for(intj=0;j< (1<<n); j + +)if(V1[j]) for(intk=0;k< (1<<n); k++)if(V2[j][k]) for(intr=cnt[j];r+cnt[k]<=k;r++) F[i][r+cnt[k]][k]+=f[i-1][r][j];  for(intI=0;i< (1&LT;&LT;N); i++) ans+=F[n][k][i]; cout<<ans<<Endl; return 0;}

Codevs 2451 Non-invasive (like ya DP)

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.