Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * ####### # *
- * # # # ###### # # # # #### # # # # # *
- * # # # # # # ## # # # # # # # *
- * # ###### ##### # # # # # #### ###### # # # *
- * # # # # ####### # # # # # # # # # *
- * # # # # # # # ## # # # # # # # *
- * # # # ###### # # # # #### # # #### ###### *
- ***************************************************************************/
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define endl '\n'
- #define pii pair<ll int,ll int>
- #define vi vector<ll int>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll int)x.size()
- #define hell 1000000007
- #define rep(i,a,b) for(ll int i=a;i<b;i++)
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define bs binary_search
- #define mp make_pair
- using namespace std;
- #define N 100005
- int a[21][21];
- ll solve(ll n,ll i, ll j)
- {
- if(a[i][j]==1)
- return 0;
- if(i==n && j==n)
- return 1;
- ll s=0;
- a[i][j]=1;
- s+=solve(n,i+1,j);
- s+=solve(n,i-1,j);
- s+=solve(n,i,j+1);
- s+=solve(n,i,j-1);
- a[i][j]=0;
- return s;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int TESTS=1;
- cin>>TESTS;
- while(TESTS--)
- {
- ll n;
- cin>>n;
- rep(i,1,n+1)
- {
- rep(j,1,n+1)
- {
- cin>>a[i][j];
- }
- }
- /*********creating boundary*************/
- rep(i,0,n+2)
- {
- a[i][0]=1;
- a[i][n+1]=1;
- }
- rep(i,1,n+1)
- {
- a[0][i]=1;
- a[n+1][i]=1;
- }
- /**************************************/
- a[0][0]=0; // because of error in problem setter's code, without this code will fail at test 8#
- // though it is not correct according to que.
- if(a[n][n]==1)
- {
- cout<<0<<endl;
- continue;
- }
- cout<<solve(n,1,1)<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment