Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. const int MAXSIZE=50;
  5. int dynLetters(int n){//where n is the length of the string - not string &alphabet as para
  6. //store the count in an array for dynLetters to retrieve it later
  7. int count;
  8. int arr[MAXSIZE];
  9.  
  10. //check for previously results and return
  11. if (alphabet[n]=='a' && alphabet[n+1]='a') return count;
  12.  
  13. //else execute the recursion base case
  14. if (n==1) count=2;
  15. else if (n==0) count=1;
  16.  
  17. else count=dynLetters(n-2) + dynLetters(alphabet,n-2);
  18.  
  19. //store the result and return its value
  20. arr[0]=count;
  21. return count;
  22. }
  23.  
  24. /*Given an 9 × 9 board with some squares already filled with hint values, the objective of the
  25. Sudoku problem is to fill all the empty squares with values in 1..9, such that each row, each
  26. column, and each of the 9 blocks are filled with distinct values.*/
  27.  
  28. bool distinctLocation(const int matrix[9], int row, int column){ //set vector to value...
  29. int distinctCol, distinctRow;
  30. for (distinctRow=0; distinctRow<row; distinctRow++){
  31. for (distinctCol=0; distinctCol<column; distinctCol++){
  32. if (matrix[distinctRow][distinctCol] == matrix[row][column]) return false;
  33. //does this check for top and bottom?
  34. }
  35. }
  36. for (distinctCol=0; distinctCol<column; distinctCol++){
  37. for (distinctRow=0; distinctRow<row; distinctRow++){
  38. if (matrix[distinctRow][distinctCol] == matrix[row][column]) return false;
  39. }
  40. return true;
  41. }
  42.  
  43. bool placeValue(const int matrix[][9], int row, int col){
  44. int row=0, col=0;
  45. bool foundLocation;
  46. if (col==9 && row==9) //stopping condition
  47. foundLocation=true;
  48. foundLocation=false;
  49.  
  50. if distinctLocation(matrix,row,col) == true){
  51. while(row<9 && col<9 && !foundLocation){
  52. queenList[col]=row;
  53. //try to place queens col 1 through 7
  54. foundLocation=placeValue(matrix[],col+1);
  55.  
  56. if (!foundLocation) {
  57. matrix[col++]=row;
  58. row++; //use next row since current row doesn't lead to solution
  59. }
  60. else row++; //current row fails go to the next row
  61. }
  62. }
  63. return safeLocation;
  64. }
  65.  
  66. bool sudoku(vector<int> &matrixList, int row){
  67. matrixList[0]=row;
  68. if (placeValue(matrixList,1)) return true;
  69. return false;
  70. }
  71.  
  72. int main(){
  73. std:: string alphabet= "abaaabaabbbbbba";
  74. std:: cout << dynLetters(alphabet,5);
  75. int row;
  76. vector<int> sudoku(9);
  77. board chessBoard;
  78. }
Add Comment
Please, Sign In to add comment