Advertisement
Guest User

Untitled

a guest
Oct 12th, 2013
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5. #include <set>
  6. #include <map>
  7. #include <list>
  8. #include <queue>
  9. #include <stack>
  10. #include <memory>
  11. #include <iomanip>
  12. #include <numeric>
  13. #include <functional>
  14. #include <new>
  15. #include <algorithm>
  16. #include <cmath>
  17. #include <cstring>
  18. #include <cstdlib>
  19. #include <cstdio>
  20. #include <climits>
  21. #include <cctype>
  22. #include <ctime>
  23.  
  24. #define REP(i, n) for(int (i) = 0; i < n; i++)
  25. #define FOR(i, a, n) for(int (i) = a; i < n; i++)
  26. #define FORR(i, a, n) for(int (i) = a; i <= n; i++)
  27. #define for_each(q, s) for(typeof(s.begin()) q=s.begin(); q!=s.end(); q++)
  28. #define sz(n) n.size()
  29. #define pb(n) push_back(n)
  30. #define all(n) n.begin(), n.end()
  31.  
  32. template<typename T> T gcd(T a, T b) {
  33.     if(!b) return a;
  34.     return gcd(b, a % b);
  35. }
  36. template<typename T> T lcm(T a, T b) {
  37.     return a * b / gcd(a, b);
  38. }
  39.  
  40. template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
  41. template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
  42. int in() { int x; scanf("%d", &x); return x; }
  43.  
  44. using namespace std;
  45.  
  46. typedef long long Int;
  47. typedef unsigned uint;
  48.  
  49. const int INF = INT_MAX / 3;
  50. const int MAXN = 2020;
  51.  
  52. int I, N, M, P;
  53. int C[MAXN], V[MAXN];
  54.  
  55. int dp[MAXN][MAXN];
  56.  
  57. string itostr(int a) {
  58.     stringstream ss; ss << a;
  59.     string ans;
  60.  
  61.     ss >> ans;
  62.  
  63.     return ans;
  64. }
  65.  
  66. int func(int curr_y, int m_age) {
  67.     if (curr_y == N) {
  68.         return 0;
  69.     }
  70.     if (m_age > M) {
  71.         return INF;
  72.     }
  73.  
  74.     if (dp[curr_y][m_age] != -1) {
  75.         return dp[curr_y][m_age];
  76.     }
  77.  
  78.     int& ans = dp[curr_y][m_age] = 0;
  79.  
  80.     int a = P - V[m_age - 1] + C[0] + func(curr_y + 1, 1);
  81.     int b = C[m_age] + func(curr_y + 1, m_age + 1);
  82.  
  83.     if (m_age == M || a <= b) {
  84.         ans = a;
  85.     } else {
  86.         ans = b;
  87.     }
  88.  
  89.     return ans;
  90. }
  91.  
  92. int main(void) {
  93.     freopen("i.in", "r", stdin);
  94.     int i;
  95.     for ( ; scanf("%d%d%d%d", &N, &I, &M, &P) == 4; ) {
  96.         for (i = 0; i < M; i++) {
  97.             C[i] = in();
  98.         }
  99.         for (i = 0; i < M; i++) {
  100.             V[i] = in();
  101.         }
  102.  
  103.         memset(dp, -1, sizeof(dp));
  104.  
  105.         int ans = func(0, I);
  106.  
  107.         printf("%d\n", ans);
  108.     }
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement