题目
分析
- n=15
- 那就枚举吧,枚举当前行刷不刷
- 然后计算出列的答案加上取min
代码
1 #include<iostream>
2 #include<cstring>
3 using namespace std;
4 int b[20][20],a[20][20],ans=100000000;
5 bool h[20],l[20],hh[20],ll[20];
6 int n,m,r,c;
7 int check()
8 {
9 int t=0;
10 memcpy(b,a,sizeof(b));
11 for (int i=1;i<=n;i++)
12 if (h[i]==1)
13 for (int j=1;j<=m;j++)
14 b[i][j]=0;
15 for (int j=1;j<=m;j++)
16 for (int i=1;i<=n;i++)
17 if (b[i][j]==1)
18 {
19 t++;
20 j+=c-1;
21 break;
22 }
23 return t;
24 }
25 void dfs(int x,int sum)
26 {
27 if (x>n)
28 {
29 ans=min(ans,sum+check());
30 return;
31 }
32 for (int i=x;i<=min(x+r-1,n);i++)
33 h[i]=1;
34 dfs(min(x+r,n+1),sum+1);
35 for (int i=x;i<=min(x+r-1,n);i++)
36 h[i]=0;
37 dfs(x+1,sum);
38 }
39 int main ()
40 {
41 cin>>n>>m;
42 char num;
43 for (int i=1;i<=n;i++)
44 for (int j=1;j<=m;j++)
45 {
46 cin>>num; if (num=='X') a[i][j]=1;
47 }
48 cin>>r>>c;
49 dfs(1,0);
50 cout<<ans;
51 }