poj 3074 poj 3076(精確覆蓋)

2021-06-22 23:03:01 字數 2063 閱讀 5926

兩個題都是數獨,題意很明確。

建圖的思路大神寫的很好:

:一共9 * 9 * 9 == 729行。一共9 * 9小格,每一格有9種可能性(1 - 9), 每一種可能都對應著一行。

:一共(9 + 9 + 9) * 9 + 81 == 324 種前面三個9分別代表著9行9列和9小 塊。乘以9的意思是9種可能,因為每種可能只可以選擇乙個。81代表著81個 小格,限制著每乙個小格只可以放乙個地方。

我個人的理解是行就是所有的可能,列就是限制條件,這裡就是列

#include #include #include #include #include #include #include #include #include #include #include using namespace std;

#define for(i,a) for(i=0;i=b;i--)

#define clr(ar,vel) memset(ar,vel,sizeof(ar))

#define pb push_back

#define maxint 0x7fffffff

int ans[300];

string s;

const int maxn = 502011;

const int head = 0;

int size;

int col[maxn];

int row[maxn];

int cell[maxn];

int r[maxn], l[maxn], u[maxn], d[maxn];

int s[maxn], c[maxn], o[maxn], h[maxn], x[maxn];

void remove(const int &c) }}

void resume(const int &c)

} l[r[c]] = c;

r[l[c]] = c;

}bool dfs(const int &k)

for(int i = 0; i < 16; i ++)

cout << endl;

} return true;

} int s(maxint), c;

for (int t = r[head]; t != head; t = r[t])

} //cout << k << endl;

remove(c);

for (int i = d[c]; i != c; i = d[i])

if (dfs(k + 1))

for (int j = l[i]; j != i; j = l[j])

} resume(c);

return false;

}void link(int r,int c)

x[size++]=r;

}void init(int m)

r[m] = 0;

l[0] = m;

size = m+1;

}int main()

//cout << s << endl;

init(1024);

rownum = 1;

int cnt = 0;

//for(int i = 0; i < 10; i ++) cout << ans[i] << ' ';cout << endl;

for(int i = 1; i <= 16; i ++)

cnt++;

}} //for(int i = 0; i < 10; i ++) cout << ans[i] << ' ';cout << endl;

//for(int i = 0; i < 324; i ++) cout << s[i] << ' ' ;cout << endl;

for(int i = 1; i <= 16; i ++)

//rownum++;}}

} dfs(0);

//cout << "answer" << endl;

}return 0;

}

poj 3740 DLX(精確覆蓋)

題意 經典的精確覆蓋問題。思路 精確覆蓋問題是npc的,用dlx能夠比較有效的搜尋。寫完兩個數獨再寫這個就不難了 實際上這個是原始問題,數獨只是dlx的應用 include include define n 16 define m 300 struct nodep n m m 5 int s n 5...

POJ 3041 Asteroids(最小點覆蓋)

poj 3041 asteroids 題意 給出m個點的所在行列,每次可以選擇清除一行或者一列,問清除這些點的最小操作次數是多少?分析 將所有點的行看成一組,所有的點列看成一組,對每個點的行和列建一條邊,每條邊就代表乙個點,清除一行或者一列可以看成選擇二分圖中的乙個點,清除所有的點,就相當於選擇二分...

POJ 3041 Asteroids 最小點覆蓋

題意 用最少的射擊來消滅圖中的小行星。關鍵是建圖轉化,建乙個 橫座標到縱座標的二分圖,有障礙的點的位置上的值賦值為1,然後根據題意求的是二分圖的最小點覆蓋數,根據乙個定理,知道最小點覆蓋數 最大匹配數 ac include include include include include includ...