POJ 1321 棋盤問題

2021-09-07 10:54:04 字數 1368 閱讀 2855

棋盤問題

time limit:1000ms

memory limit:10000k

total submissions:21666

accepted:10765

description

在乙個給定形狀的棋盤(形狀可能是不規則的)上面擺放棋子,棋子沒有差別。要求擺放時隨意的兩個棋子不能放在棋盤中的同一行或者同一列,請程式設計求解對於給定形狀和大小的棋盤,擺放k個棋子的全部可行的擺放方案c。

input

輸入含有多組測試資料。 

每組資料的第一行是兩個正整數,n k。用乙個空格隔開,表示了將在乙個n*n的矩陣內描寫敘述棋盤,以及擺放棋子的數目。 n <= 8 , k <= n 

當為-1 -1時表示輸入結束。 

隨後的n行描寫敘述了棋盤的形狀:每行有n個字元。當中 # 表示棋盤區域。 . 表示空白區域(資料保證不出現多餘的空白行或者空白列)。 

output

對於每一組資料。給出一行輸出,輸出擺放的方案數目c (資料保證c<2^31)。

sample input

2 1

#..#

4 4...#

..#.

.#..

#...

-1 -1

sample output

2

1

深搜。注意k

#include#include#include#includeusing namespace std;

int n , k;

int chess[10][10];

int vist[10];

int ans;

void dfs(int x, int num)

if(x>n)

return ;

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

}dfs(x+1, num);

}int main()

dfs(1, 0);

cout<

#include#include#include#includeusing namespace std;

#define max 100

char map[max][max];

int s[max];

int n,k,i,j,a;

void dfs(int x,int y) //函式參量表示的意思:x表示該棋盤的第x行,y表示放置第y個棋子

} } } } int main () dfs(0,0); printf("%d\n",a); } return 0; }

POJ 1321 棋盤問題

time limit 1000ms memory limit 10000k total submissions 7007 accepted 3390 description 在乙個給定形狀的棋盤 形狀可能是不規則的 上面擺放棋子,棋子沒有區別。要求擺放時任意的兩個棋子不能放在棋盤中的同一行或者同一列...

poj 1321 棋盤問題

棋盤問題 time limit 1000ms memory limit 10000k total submissions 15365 accepted 7600 description 在乙個給定形狀的棋盤 形狀可能是不規則的 上面擺放棋子,棋子沒有區別。要求擺放時任意的兩個棋子不能放在棋盤中的同一...

POJ 1321 棋盤問題

找到第乙個有 的行開始回溯就可以了 include include using namespace std const int maxn 9 char board maxn maxn bool c maxn int ans,n,k void backtracking int curi,int cnt...