Meaning of the questions:
Given a $ N \ times M $ 01 to $ $ matrix, to cover all positions $ 1 $, find the minimum number of operations. In one operation, on end cover can be up to $ C $ continuous column, a continuous covering or sideways up to $ R $ row.
$ 1 \ le \, N \; M, \; R, \, C \ the \; $ 15
analysis:
Smaller data range, consider enumeration.
Enumeration but not blindly while covering row, overwriting the column, since this enumeration is $ O (2 ^ {2N} ) $ , and T will be $ $.
Consider enumeration overwriting row, column cover pieces greedy calculated to obtain a solution after the operation, is completed.
The total time complexity $ O (N ^ 3 \ times 2 ^ N) $.
achieve:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define IL inline using namespace std; const int N=15; int n,m,r,c; int bod[N+3][N+3]; int clm[N+3]; int tbod[N+3][N+3]; int tclm[N+3]; int main(){ scanf("%d %d\n",&n,&m); memset(bod,0,sizeof bod); for(int i=0;i<n;i++){ char ch; for(int j=0;j<m;j++){ scanf("%c",&ch); bod[i][j]=ch=='X'; } scanf("\n"); } scanf("%d %d\n",&r,&c); memset(clm,0,sizeof clm); for(int i=0;i<m;i++) for(int j=0;j<n;j++) clm[i]+=bod[j][i]; memcpy(tbod,bod,sizeof bod); memcpy(tclm,clm,sizeof clm); int ans=min(n/r+1,m/c+1); for(int S=0;S<(1<<n);S++){ int cnt=0; for(int i=0;i<n;i++) if(S>>i&1){ cnt++; for(int j=0;j<r;j++) for(int k=0;k<m;k++) if(bod[i+j][k]==1){ bod[i+j][k]=0; clm[k]--; } } for(int i=0;i<m;i++) if(clm[i]>0){ cnt++; for(int j=0;j<c;j++) clm[i+j]=0; } memcpy(bod,tbod,sizeof tbod); memcpy(clm,tclm,sizeof tclm); ans=min(ans,cnt); } printf("%d",ans); return 0; }
summary:
Consider pruning the search, but also consider the optimization of the structure of the search bar.