Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[101][101], n, m, l, c;
- int sum(int l1, int c1, int l2, int c2)
- {
- if((l1 > l2) || (c1 > c2)) return 0;
- else
- if((l1 == l2) && (c1 == c2))
- if(a[l1][c1] % 2 == 0)return a[l1][c1];
- else return 0;
- else
- {
- int s = 0;
- int lm = (l1 + l2) / 2;
- int cm = (c1 + c2) / 2;
- s += sum(l1, c1, lm, cm);
- s += sum(l1, cm + 1, lm, c2);
- s += sum(lm + 1, c1, l2, cm);
- s += sum(lm + 1, cm + 1, l2, c2);
- return s;
- }
- }
- int main()
- {
- int i, j;
- cin >> n>> m;
- for(i = 1;i <= n; i++)
- for(j = 1; j<= m;j++)
- cin >> a[i][j];
- cout << sum(1, 1, n, m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement