voiddfs(vector<vector<int> >& martrix, int x, int y, int k){ int m = martrix.size(), n = martrix[0].size(); //base case if(x > m || y > n) return; //原来就不可以放 if(martrix[x][y] == 0) return; //变为不可放 martrix[x][y] = 0; k++; if(k == 2){ //答案加一 res++; return; } dfs(martrix, x, y + 1, k); }
intmain(){ int M; cin >> N >> M; vector<int> nums(M); int minNum = INT_MAX; for(int i = 0; i < M; i++){ cin >> nums[i]; if(nums[i] < minNum){ minNum = nums[i]; } } //处理数组 vector<vector<int> > matrix(abs(minNum), vector<int> (M, 0)); for(int i = 0; i < M; i++){ if(nums[i] < 0){ int j = abs(nums[i]); int k = 0; while(k < j){ matrix[k++][i] = 1; } } } //dfs for(int i = 0; i < matrix.size(); i++){ for(int j = 0; j < matrix[0].size(); j++){ if(matrix[i][j] == 1){ dfs(matrix, i, j, 0); } } } cout << res << endl; return0; }