-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathN_Sum_of_a_Matrix.cpp
More file actions
65 lines (50 loc) · 1.09 KB
/
N_Sum_of_a_Matrix.cpp
File metadata and controls
65 lines (50 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Mohit Verma "mohitvdx"
// problem:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;
void rec(int i, int j, int r, int c, vector<vector<int>>& sum, vector<vector<int>>& a, vector<vector<int>>& b){
if(i>=r || j>=c){
return;
}
if(sum[i][j]!=0){
return;
}
sum[i][j] = a[i][j] + b[i][j];
rec(i+1, j, r, c, sum, a, b);
rec(i, j+1, r, c, sum, a, b);
}
void solve(){
int r, c; cin>>r>>c;
vector<vector<int>> a(r, vector<int> (c));
vector<vector<int>> b(r, vector<int> (c));
vector<vector<int>> sum(r, vector<int> (c,0));
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin>>a[i][j];
}
}
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin>>b[i][j];
}
}
rec(0,0,r,c, sum, a, b);
for(auto k:sum){
for(auto l: k){
cout<<l<<" ";
}
cout<<'\n';
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(NULL); // fast IO
// int t; cin>>t;
// while(t--){
solve();
// }
}
/*
*/