problem while declaring a 3d array

Правка en1, от abhinav700, 2022-08-01 07:43:12

i am doing a leetCode question which requires a 3d array for memorisation. i have followed every rule of using the memset function and creating the arrays still the array is not getting initialised with the value specified in memset function. I have been stuck on this from yesterday. Can someone pls help? Problem Link: https://leetcode.com/problems/knight-probability-in-chessboard/

CODE:


class Solution { public: int dir[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{2,-1},{2,1},{1,2},{1,-2}}; double solve(int n,int k,int r,int c,double dp[101][26][26]){ if(r<0 || r>=n || c<0 || c>=n) return 0; if(k==0) return 1.0; if(dp[k][r][c]!=2.0){ cout<<"k r,c : "<<k<<" "<<r<<" "<<c<<endl; cout<<"value : "<<dp[k][r][c]<<endl<<endl; return dp[k][r][c]; } double rate=0; for(int i=0;i<8;i++){ rate+=(solve(n,k-1,r+dir[i][0],c+dir[i][1],dp)*0.125); } return dp[k][r][c]= rate; } double knightProbability(int n, int k, int row, int column) { double dp[101][26][26]; memset(dp,2.0,sizeof(dp[0][0][0])); cout<<dp[0][0][0]; solve(n,k,row,column,dp); return dp[k][row][column]; } };
Теги c++, help, array

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский abhinav700 2022-08-01 07:43:12 1372 Initial revision (published)