[C++] | DP + MATH (+ atcoder editorial)
A similar question came ino an Atcoder contest:-\nquestion Link -https://atcoder.jp/contests/abc202/tasks/abc202_d\neditorial Link - https://atcoder.jp/contests
A similar question came ino an Atcoder contest:-\nquestion Link -[https://atcoder.jp/contests/abc202/tasks/abc202_d]()\neditorial Link - [https://atcoder.jp/contests/abc202/editorial/1893](http://)\n\n```\nclass Solution {\npublic:\n    int ncr[31][31];\n    string kthSmallestPath(vector<int>& destination, int k) {\n\n        // calculating the combination values\n        for(int n=1;n<31;++n)\n        {\n            ncr[n][0]=1;\n            for(int r=1;r<n;++r)\n            {\n                ncr[n][r]=ncr[n-1][r]+ncr[n-1][r-1];\n            }\n            ncr[n][n]=1;\n\n        }\n        string res="";\n        int H=destination[1];\n        int V=destination[0];\n        \n        while(H!=0 && V!=0)\n        {\n            int ways=ncr[H+V-1][H-1];\n            \n            \n            if(ways>=k)\n            {\n                res+=\'H\';\n                H--;\n            }\n            else\n            {\n                res+=\'V\';\n                k-=ways;\n                V--;\n            }\n        }\n        while(H--)\n            res+=\'H\';\n        while(V--)\n            res+=\'V\';\n        return res;\n    }\n};\n```
[]