| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:简单In Reply To:简单 Posted by:when at 2016-11-26 11:12:49 > #include <iostream>
> #include <cstring>
> using namespace std;
>
> const int ROW = 10;
> const int COL = 10;
>
> int book[COL];
> char chess[ROW][COL];
> int step, n;
> long long sum;
>
>
> void DFS(char chess[][COL], int row,int k) {
> if (row > n)
> return;
> if (k == step) {
> sum++;
> return;
> }
>
> for (int j = 1; j <= 2; j++) {
> if (j == 1)
> DFS(chess, row + 1, k); //每一行都有两种选择,放或不放
> if (j == 2) {
> for (int i = 0; i < n; i++) {
> if (book[i] == 0 && chess[row][i] == '#') {
> book[i] = 1;
> DFS(chess, row + 1, k + 1);
> book[i] = 0;
> }
> }
> }
> }
> }
>
>
> int main() {
> while (cin >> n >> step) {
> sum = 0;
> cin.get();
> if (n == -1 && step == -1)
> break;
> for (int i = 0; i < n; i++)
> cin >> chess[i];
>
> DFS(chess, 0, 0);
>
>
>
> cout << sum << endl;
> }
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator