El juego de Taojiang y Cece nuevamente (por el escritor de conciencia wzc) (pensamiento + presión estatal dp)

https://ac.nowcoder.com/acm/contest/12482/D


 

Significado de la pregunta: https://blog.csdn.net/zstuyyyyccccbbbb/article/details/115171072 Sobre la base de la pregunta original, no se pueden colocar algunos puntos.

Idea: combine estos no colocables en el st [] preprocesado. Aquí necesitamos abrir st [] [] en dos dimensiones para registrar la viabilidad del estado de la i-ésima columna y j.

detalle:

1. Convierta la acumulación de números no almacenables en binarios (indicados como temp), recorra todo [estado y temp], si == 1 significa que el estado no almacenable está incluido y márquelo como no

2. Debido a la limitación de no almacenamiento, afecta la viabilidad de la fila única / fila única original.

Tal como:

temp: 0 0 1 0 1 0 0 (el marcado con 1 es X)

j: 0 1 0 1 0 0 0

De esta manera, juzgar directamente la paridad 0 continua de j causará problemas, entonces x == (j | temp), y luego el juicio de paridad 0 continua con x, y el resultado marcará el estado de j

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=13;
typedef int LL;
typedef pair<LL,LL>P;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
bool st[maxn][1<<maxn];///每一列的可行状态
long long dp[maxn][1<<maxn];
bool map1[maxn][maxn];
int main(void)
{
  LL n,m,k;
  while(scanf("%d%d%d",&n,&m,&k)!=0){
     if(n==0&&m==0&&k==0) break;
     memset(map1,0,sizeof(map1));
     for(LL i=1;i<=k;i++){
        LL x,y;
        scanf("%d",&x);scanf("%d",&y);
        map1[x][y]=true;
     }

     for(LL i=1;i<=m;i++){///枚举每一列
         LL temp=0;
         for(LL j=1;j<=n;j++){///该列的每一行
            if(map1[j][i]) temp+=(1<<(j-1));
         }
         for(LL j=0;j<(1<<n);j++){///该列的全状态
             st[i][j]=true;
             if( j&(temp) ) {st[i][j]=false;continue;}
             LL x=j|temp;///细节
             LL cnt=0;
             for(LL k=1;k<=n;k++){
                 if( ( 1<<(k-1) ) &x ){
                    if(cnt&1){
                        st[i][j]=false;break;
                    }
                    else cnt=0;
                 }
                 else cnt++;
             }
             if(cnt&1) st[i][j]=false;
         }
     }
     memset(dp,0,sizeof(dp));
     dp[0][0]=1;
     for(LL i=1;i<=m;i++){
        for(LL j=0;j<(1<<n);j++){
            for(LL k=0;k<(1<<n);k++){
                if((j&k)==0&&st[i][j|k]==true){
                    dp[i][j]+=dp[i-1][k];
                }
            }
        }
     }
     printf("%lld\n",dp[m][0]);
  }
return 0;
}

 

Supongo que te gusta

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/115180935
Recomendado
Clasificación