标签:ret rip 正整数 idt int sum lang ted long
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 38214 | Accepted: 18724 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 const int ROW = 10; 6 const int COL = 10; 7 8 int book[COL]; 9 char chess[ROW][COL]; 10 int step, n; 11 long long sum; 12 13 14 void DFS(char chess[][COL], int row,int k) { //row代表行数。k代表放置的旗子个数。 15 if (row > n) 16 return; 17 if (k == step) { 18 sum++; 19 return; 20 } 21 22 for (int j = 1; j <= 2; j++) { 23 if (j == 1) //代表该行不放置棋子 24 DFS(chess, row + 1, k); 25 if (j == 2) { //该行放置棋子 26 for (int i = 0; i < n; i++) { 27 if (book[i] == 0 && chess[row][i] == ‘#‘) { 28 book[i] = 1; 29 DFS(chess, row + 1, k + 1); 30 book[i] = 0; 31 } 32 } 33 } 34 } 35 } 36 37 38 int main() { 39 while (cin >> n >> step) { 40 sum = 0; 41 cin.get(); 42 if (n == -1 && step == -1) 43 break; 44 for (int i = 0; i < n; i++) 45 cin >> chess[i]; 46 47 DFS(chess, 0, 0); 48 49 50 51 cout << sum << endl; 52 } 53 }
标签:ret rip 正整数 idt int sum lang ted long
原文地址:http://www.cnblogs.com/IKnowYou0/p/6103795.html