fork download
  1. int n;
  2. int m;
  3. int d;
  4.  
  5. int cord[501];
  6. int cost[501];
  7. int dp[501][501][501];
  8. int findans(int i, int prev, int m)
  9. {
  10.  
  11. if (i <= 0)
  12. return 0;
  13.  
  14. if (m <= 0)
  15. return INT_MAX;
  16.  
  17.  
  18. if (dp[i][prev][m] != -1)
  19. return dp[i][prev][m];
  20.  
  21.  
  22. int ans = INT_MAX;
  23.  
  24. for (int j = i; j >= 1; j--)
  25. {
  26. if (j == 1)
  27. {
  28. ans = min(findans(j - 1, j, m) + (cord[prev] - cord[j]) * (cost[j]), ans);
  29. }
  30. else
  31. {
  32. if (m > 0)
  33. {
  34. int res = min(findans(j - 1, prev, m - 1), findans(j - 1, j, m) + (cord[prev] - cord[j]) * (cost[j]));
  35. ans = min(ans, res);
  36. }
  37. else
  38. ans = min(ans, findans(j - 1, j, m) + (cord[prev] - cord[j]) * (cost[j]));
  39. }
  40. }
  41.  
  42. return dp[i][prev][m] = ans;
  43. }
  44. void solve()
  45. {
  46. cin >> n >> d >> m;
  47. for (int i = 1; i <= n; i++)
  48. {
  49. cin >> cord[i];
  50. }
  51. for (int i = 1; i <= n; i++)
  52. {
  53. cin >> cost[i];
  54. }
  55. cord[n + 1] = d;
  56. memset(dp, -1, sizeof(dp));
  57.  
  58. int ans = findans(n, n + 1, m);
  59. cout << ans << endl;
  60. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int findans(int, int, int)’:
prog.cpp:15:22: error: ‘INT_MAX’ was not declared in this scope
               return INT_MAX;
                      ^~~~~~~
prog.cpp:15:22: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 int n;
prog.cpp:15:22:
               return INT_MAX;
                      ^~~~~~~
prog.cpp:22:18: error: ‘INT_MAX’ was not declared in this scope
        int ans = INT_MAX;
                  ^~~~~~~
prog.cpp:22:18: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:28:28: error: ‘min’ was not declared in this scope
                      ans = min(findans(j - 1, j, m) + (cord[prev] - cord[j]) * (cost[j]), ans);
                            ^~~
prog.cpp:34:39: error: ‘min’ was not declared in this scope
                             int res = min(findans(j - 1, prev, m - 1), findans(j - 1, j, m) + (cord[prev] - cord[j]) * (cost[j]));
                                       ^~~
prog.cpp:38:35: error: ‘min’ was not declared in this scope
                             ans = min(ans, findans(j - 1, j, m) + (cord[prev] - cord[j]) * (cost[j]));
                                   ^~~
prog.cpp: In function ‘void solve()’:
prog.cpp:46:8: error: ‘cin’ was not declared in this scope
        cin >> n >> d >> m;
        ^~~
prog.cpp:56:8: error: ‘memset’ was not declared in this scope
        memset(dp, -1, sizeof(dp));
        ^~~~~~
prog.cpp:56:8: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
prog.cpp:1:1:
+#include <cstring>
 int n;
prog.cpp:56:8:
        memset(dp, -1, sizeof(dp));
        ^~~~~~
prog.cpp:59:8: error: ‘cout’ was not declared in this scope
        cout << ans << endl;
        ^~~~
prog.cpp:59:8: note: suggested alternative: ‘cost’
        cout << ans << endl;
        ^~~~
        cost
prog.cpp:59:23: error: ‘endl’ was not declared in this scope
        cout << ans << endl;
                       ^~~~
prog.cpp:59:23: note: suggested alternative: ‘enum’
        cout << ans << endl;
                       ^~~~
                       enum
stdout
Standard output is empty