Saleh127

UVA 11195

Mar 1st, 2021
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. char a[100][100];
  6. ll cc[100],rec[100],dia[100];
  7. ll n,ans=0;
  8.  
  9. void dfs(ll r)
  10. {
  11. if(r==n)
  12. {
  13. ans++;
  14. return;
  15. }
  16. for(ll i=0;i<n;i++)
  17. {
  18. if(cc[i]==0 && rec[r+i]==0 && dia[(n-1+r-i)]==0 && a[r][i]=='.')
  19. {
  20. cc[i]=rec[r+i]=dia[(n-1+r-i)]=1;
  21. dfs(r+1);
  22. cc[i]=rec[r+i]=dia[(n-1+r-i)]=0;
  23. }
  24. }
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);cout.tie(0);
  32.  
  33. ll o=1,i,j;
  34.  
  35. while(cin>>n && n)
  36. {
  37. char x;
  38. for(i=0;i<n;i++)
  39. {
  40. for(j=0;j<n;j++)
  41. {
  42. cin>>a[i][j];
  43. }
  44. }
  45. dfs(0);
  46.  
  47. cout<<"Case "<<o++<<": "<<ans<<endl;
  48. ans=0;
  49.  
  50. memset(a,0,sizeof(a));
  51. memset(cc,0,sizeof(cc));
  52. memset(rec,0,sizeof(rec));
  53. memset(dia,0,sizeof(dia));
  54.  
  55. }
  56.  
  57.  
  58. return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment