都知道是枚举行移动 枚举列移动
脑子不清楚 一开始写的很shit,后来动了一下脑子,发现你可以处理行移动,然后在行移动的基础上处理列移动,注意RE问题就行了
class Solution {
public:int largestOverlap(vector<vector<int>>& img1, vector<vector<int>>& img2) {int n = img1.size();int m = img2.size();int ans = 0;//hang 偏移 -n - n//lie 偏移 -m - mint n1 = n-1,m1 = m-1;for(int i=-n1;i<=n1;i++)for(int j=-m1;j<=m1;j++){vector<vector<int>>v(n+10,vector<int>(m,0));for(int i1=0;i1<n;i1++)for(int j1=0;j1<m;j1++)if(i1+i>=0&&i1+i<n)v[i1][j1] = img1[i1+i][j1];vector<vector<int>>v1(n+10,vector<int>(m,0));for(int i1=0;i1<n;i1++)for(int j1=0;j1<m;j1++)if(j1+j>=0&&j1+j<m)v1[i1][j1] = v[i1][j1+j];int tem = 0;for(int i1=0;i1<n;i1++)for(int j1=0;j1<m;j1++)if(v1[i1][j1]&img2[i1][j1])tem++;ans = max(ans,tem);} return ans;}
};