Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int d[6], c[6], a[6][6];
- void output(){
- for(int i = 1; i <= 5; i++){
- for(int j = 1; j <= 5; j++)
- cout << a[i][j] << " ";
- cout << "\n";
- }
- exit(0);
- }
- void dq(int i, int j) {
- if (i == 6) {
- if (c[5] == 0) output();
- return ;
- }
- int l = max(1, max(d[i]-25*(5-j), c[j]-25*(5-i)));
- int r = min(25, min(d[i]-5+j, c[j]-5+i));
- if (l > 25 || r < 1 || l > r) return ;
- if (j == 5) l = r = d[i];
- for(int x = l; x <= r; x++) {
- a[i][j] = x;
- d[i] -= x;
- c[j] -= x;
- if (j < 5) dq(i, j+1);
- else dq(i+1, 1);
- d[i] += x;
- c[j] += x;
- a[i][j] = 0;
- }
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- for(int i = 1; i <= 5; i++)
- cin >> d[i];
- for(int i = 1; i <= 5; i++)
- cin >> c[i];
- dq(1,1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement