日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ZOJ 3209

發布時間:2025/3/15 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZOJ 3209 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

精確覆蓋

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std;const int maxn=920; const int maxnode=920*550; const int maxr=550; int ans; struct DLX {int n , sz; // 行數,節點總數int S[maxn]; // 各列節點總數int row[maxnode],col[maxnode]; // 各節點行列編號int L[maxnode],R[maxnode],U[maxnode],D[maxnode]; // 十字鏈表int ansd; // 解void init(int n ){this->n = n ;for(int i = 0 ; i <= n; i++ ){U[i] = i ;D[i] = i ;L[i] = i - 1;R[i] = i + 1;}R[n] = 0 ;L[0] = n;sz = n + 1 ;memset(S,0,sizeof(S));}void addRow(int r,vector<int> c1){int first = sz;for(int i = 0 ; i < c1.size(); i++ ){int c = c1[i];L[sz] = sz - 1 ; R[sz] = sz + 1 ; D[sz] = c ; U[sz] = U[c];D[U[c]] = sz; U[c] = sz;row[sz] = r; col[sz] = c;S[c] ++ ; sz ++ ;}R[sz - 1] = first ; L[first] = sz - 1;}// 順著鏈表A,遍歷除s外的其他元素#define FOR(i,A,s) for(int i = A[s]; i != s ; i = A[i])void remove(int c){L[R[c]] = L[c];R[L[c]] = R[c];FOR(i,D,c)FOR(j,R,i) {U[D[j]] = U[j];D[U[j]] = D[j];--S[col[j]];}}void restore(int c){FOR(i,U,c)FOR(j,L,i) {++S[col[j]];U[D[j]] = j;D[U[j]] = j; }L[R[c]] = c;R[L[c]] = c;}void dfs(int d){if(d>=ans) return ;if(R[0] == 0 ){ansd = d;ans=min(ans,ansd);}// 找S最小的列cint c = R[0] ;FOR(i,R,0) if(S[i] < S[c]) c = i;remove(c);FOR(i,D,c){FOR(j,R,i) remove(col[j]);dfs(d + 1);FOR(j,L,i) restore(col[j]);}restore(c);}bool solve(){dfs(0);} };DLX solver;int main(){int T; int n,m ,p; int xx1,xx2,yy1,yy2;vector<int>colmuns;scanf("%d",&T);while(T--){ans=(1<<30);scanf("%d%d%d",&n,&m,&p);solver.init(n*m);for(int k=1;k<=p;k++){colmuns.clear();scanf("%d%d%d%d",&xx1,&yy1,&xx2,&yy2);for(int i=xx1+1;i<=xx2;i++){for(int j=yy1+1;j<=yy2;j++){colmuns.push_back((i-1)*m+j);}}solver.addRow(k,colmuns);}solver.solve();if(ans==(1<<30)) printf("-1\n");else printf("%d\n",ans);}return 0; }

  

轉載于:https://www.cnblogs.com/jie-dcai/p/3936489.html

總結

以上是生活随笔為你收集整理的ZOJ 3209的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。