2016弱校联盟十一专场10.7(12点场)-M. Subimage Recognition
2016-10-07 16:11
330 查看
M. Subimage Recognition
Time Limit: 1000msCase Time Limit: 1000msMemory Limit: 131072KB64-bit integer IO format: %lld Java class name: MainSubmit StatusFont Size: + -An image A is said to be a subimage of another image B if it is possible to removesome rows and/or columns of pixels fromB so that the resulting image is identical to A. Figure 6 illustratesan example. Image A, shown in Figure 6(a), is a subimage of image B, shown in Figure 6(b), because the imageresulting from the removal of the middle row and column of pixels fromB is identical to A.(a) Image A | (b) Image B |
Input
The input contains a single test case. The first line contains two integers r and c (1≤ r, c ≤ 20), the dimensions of A.The following r lines, each containing a string of length c, give an r × c 0-1matrix representing the pixels of A. The next line contains two integers R and C (r ≤ R ≤20; c ≤ C ≤ 20), the dimensions of B.The following R lines, each containing a string of length C, give an R × C 0-1matrix representing the pixels of B. A 0 indicates a white pixel; a 1 indicates a black pixel.Output
If A is a subimage of B, print “Yes”;otherwise, print “No”.Sample Input
2 2 11 10 3 3 101 000 100
Sample Output
Yes
题目大意:给出两个图A和B,如果在B中删去某些行某些列得到的图形与A相同的输出Yes
否则输出No
解题思路:k从第1行到第r2-r1+1行进行匹配,
从第一列开始深搜,当列数大于c1时return,
从第k行到第r2行匹配,如果成果返回1,否则返回0;
#include<iostream>using namespace std;int A[25][25],B[25][25];int col[25];int r1,c1,r2,c2;int k,cnt;bool flag;bool check(){int r=1;int i,j;for(i=k;i<=r2;i++){for(j=1;j<=c1;j++){if(A[r][j]!=B[i][col[j]])break;}if(j>c1){r++;if(r>r1)break;}}if(r==(r1+1)) return 1;return 0;}void dfs(int x){if(cnt>c1){flag=check();return ;}if(x>c2) return ;col[cnt++]=x;dfs(x+1);if(flag) return ;cnt--;dfs(x+1);}int main(){ios::sync_with_stdio(false);cin.tie(0);int i,j;char ch;cin>>r1>>c1;for(i=1;i<=r1;i++){for(j=1;j<=c1;j++){cin>>ch;A[i][j]=ch-'0';}}cin>>r2>>c2;for(i=1;i<=r2;i++){for(j=1;j<=c2;j++){cin>>ch;B[i][j]=ch-'0';}}flag=0;for(k=1;k<=r2-r1+1;k++){if(flag) break;cnt=1;dfs(1);}//cout<<col[1]<<" "<<col[2]<<endl;if(flag) cout<<"Yes"<<endl;else cout<<"No"<<endl;return 0;}
相关文章推荐
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing bnu 52325
- 2016弱校联盟十一专场10.7(12点场)-D. Blocks
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing
- 2016弱校联盟十一专场10.7(12点场) E. Training little cats
- POJ 3735 Training little cats(矩阵乘法 + 稀疏矩阵优化)——2016弱校联盟十一专场10.7(12点场)
- POJ 3600 Subimage Recognition 搜索
- [POJ3600]Subimage Recognition(状态压缩,枚举,暴力)
- 2016弱校联盟十一专场10.2部分题解
- Subimage Recognition
- 深度学习研究理解10:Very Deep Convolutional Networks for Large-Scale Image Recognition
- [弱校联萌2016]2016弱校联盟十一专场10.5
- 2016弱校联盟十一专场10.2——Around the World
- [弱校联萌2016]2016弱校联盟十一专场10.3
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- Subimage Recognition
- [Contests]2016弱校联盟十一专场10.7
- 2016弱校联盟十一专场10.5 I Increasing or Decreasing(数位dp)
- 2016弱校联盟十一专场10.3,BNU52308,大模拟