99% c++  solution
\n int i,j,k;\n        vector<int>dp(n,0);\n        dp[0]=1;\n        k=p.size();\n        vector<int>last(p.size(),0);\n        vector<int>value(p.size(),0);\n
```\n int i,j,k;\n        vector<int>dp(n,0);\n        dp[0]=1;\n        k=p.size();\n        vector<int>last(p.size(),0);\n        vector<int>value(p.size(),0);\n        for(i=0;i<k;i++)\n        {\n            value[i]=p[i];\n        }\n        int m;\n        for(i=1;i<n;i++)\n        {    \n            m=INT_MAX;\n            for(j=0;j<k;j++)\n            {\n                if(value[j]<m)\n                {\n                    m=value[j];\n                }\n            }\n            \n            dp[i]=m;\n\n            for(j=0;j<k;j++)\n            {\n                if(m==value[j])\n                {\n                    last[j]++;\n                    value[j]=p[j]*dp[last[j]];\n    \n                }\n            }\n            \n            \n        }\n\n        return  dp[n-1];\n        \n\t\t```
[]