设为首页 加入收藏

TOP

FZU 1686 神龙的难题 重复覆盖
2015-07-20 17:34:07 来源: 作者: 【 】 浏览:2
Tags:FZU 1686 神龙 难题 重复 覆盖

转换成0,1模型就好了,注意数据范围


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
          #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                using namespace std; const int MaxM = 500; const int MaxN = 500; const int maxnode = MaxM*MaxN; int K,n,m; struct DLX { int n,m,size; int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode]; int H[MaxN],S[MaxM]; int ands,ans[MaxN]; void init(int _n,int _m) { ands=0x3f3f3f3f; n = _n; m = _m; for(int i = 0;i <= m;i++) { S[i] = 0; U[i] = D[i] = i; L[i] = i-1; R[i] = i+1; } R[m] = 0; L[0] = m; size = m; for(int i = 1;i <= n;i++) H[i] = -1; } void Link(int r,int c) { ++S[Col[++size]=c]; Row[size] = r; D[size] = D[c]; U[D[c]] = size; U[size] = c; D[c] = size; if(H[r] < 0)H[r] = L[size] = R[size] = size; else { R[size] = R[H[r]]; L[R[H[r]]] = size; L[size] = H[r]; R[H[r]] = size; } } void remove(int c) { for(int i = D[c];i != c;i = D[i]) L[R[i]] = L[i], R[L[i]] = R[i]; } void resume(int c) { for(int i = U[c];i != c;i = U[i]) L[R[i]]=R[L[i]]=i; } bool v[maxnode]; int f() { int ret = 0; for(int c = R[0];c != 0;c = R[c])v[c] = true; for(int c = R[0];c != 0;c = R[c]) if(v[c]) { ret++; v[c] = false; for(int i = D[c];i != c;i = D[i]) for(int j = R[i];j != i;j = R[j]) v[Col[j]] = false; } return ret; } void Dance(int d) { if(d+f()>=ands) return; if(R[0] == 0) {ands=min(ands,d);return;} int c = R[0]; for(int i = R[0];i != 0;i = R[i]) if(S[i] < S[c]) c = i; for(int i = D[c];i != c;i = D[i]) { remove(i); for(int j = R[i];j != i;j = R[j])remove(j); Dance(d+1); for(int j = L[i];j != i;j = L[j])resume(j); resume(i); } } }g; int mp[20][20],sa,sb,id[20][20]; int main() { while(~scanf("%d%d",&n,&m)) { int tot=0; for(int i=0;i
               
                

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 3455 Leap Frog(线性DP) 下一篇动态树之详解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)