1643. Kth Smallest Instructions.cpp
Code\n\nclass Solution {\npublic:\n    string res;\n    int cnt[16][16];\n    string kthSmallestPath(vector<int>& des, int k) {\n          int m=des[0]+1,n=des[
**Code**\n```\nclass Solution {\npublic:\n    string res;\n    int cnt[16][16];\n    string kthSmallestPath(vector<int>& des, int k) {\n          int m=des[0]+1,n=des[1]+1; \n          for(int x = m-1; x>=0; x--){\n              for(int y = n-1; y>=0; y--){\n                  if(x==m-1 || y==n-1){\n                      cnt[x][y] = 1; \n                      continue;\n                  }\n                  cnt[x][y] = cnt[x][y+1] + cnt[x+1][y];\n              }\n          }\n          int i = 0, j = 0;\n          while(i<m-1 && j<n-1){\n              if(k<=cnt[i][j+1]){\n                  res+="H";j++;\n              }else{\n                  k=k-cnt[i][j+1];\n                  res+="V";i++;\n              }\n          }\n        \n          while(j++<n-1) res+="H";\n          while(i++<m-1) res+="V";             \n         return res;\n    }\n};\n```
['C']