#include<bits/stdc++.h>usingnamespacestd;
constint MAX_N = 10;
int a[MAX_N]={1, 2, 4, 7};
int n, k;
void input() {
n = 3;
// a = {1, 2, 4, 7};
k = 15;
}
bool dfs(int i, int sum) {
if (i == n)return sum == k;
if (dfs(i + 1, sum))returntrue;
if (dfs(i + 1, sum + a[i]))returntrue;
returnfalse;
}
int main() {
if (dfs(0, 0))printf("Yes\n");
elseprintf("No\n");
return0;
}
#include<bits/stdc++.h>usingnamespacestd;
constint MAX_N = 20;
int a[MAX_N];
int n, k;
bool dfs(int i, int sum) {
if (i == n)return sum == k;
if (dfs(i + 1, sum))returntrue;
if (dfs(i + 1, sum + a[i]))returntrue;
returnfalse;
}
int main() {
while (~scanf("%d", &n)) {
int tot = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
tot += a[i];
}
if (tot % 2 == 0) {
k = tot / 2;
if (dfs(0, 0))
printf("Of course,I can!\n");
elseprintf("Sorry,I can't!\n");
} elseprintf("Sorry,I can't!\n");
}
return0;
}
#include<stdio.h>constint MAX_N = 100;
constint MAX_M = 100;
int N, M;
char field[MAX_N][MAX_M + 1];
void dfs(int x, int y) {
field[x][y] = '.';
for (int dx = -1; dx <= 1; dx++)
for (int dy = -1; dy <= 1; dy++) {
int nx = x + dx;
int ny = y + dy;
if (nx >= 0 && nx < N && 0 <= y && ny < M && field[nx][ny] == 'W')dfs(nx, ny);
}
}
void solve() {
int res = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) {
if (field[i][j] == 'W') {
dfs(i, j);
++res;
}
}
printf("%d\n", res);
}
int main() {
while(~scanf("%d%d", &N, &M)) {
for (int i = 0; i < N; i++)
scanf("%s", field[i]);
solve();
}
return0;
}