#include #include #include #include using namespace std; int memo[205][205][205]; int p[205],q[206]; int getcost(int from, int to, int d) { if (from>to) return q[from]*d; if (memo[from][to][d]>=0) return memo[from][to][d]; for (int i=from; i<=to; i++) { int t = getcost(from,i-1,d+1)+getcost(i+1,to,d+1); t += (d+1)*p[i]; if (t>=0 && (memo[from][to][d]<0 || t> n && n) { for (int i=0; i> p[i]; for (int j=0; j> q[i]; cout << getcost(0,n-1,0) << endl; } return 0; }