Advertisement
Guest User

Pilots Bottom-up

a guest
Jun 9th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f(i,a,b) for(int i = (a); i <= (b); i++)
  3. using namespace std;
  4.  
  5. const int INF = 2000000007;
  6. int A[10005], B[10005], DP[5005][5005], N;
  7.  
  8. int main()
  9. {
  10.     cin >> N;
  11.     int ans = 0;
  12.     f(i,1,N) cin >> A[i] >> B[i];
  13.     f(i,0,N/2) f(j,0,N/2) DP[i][j] = INF;
  14.     DP[0][0] = 0;
  15.     f(j,0,N/2) f(i,0,j)
  16.     {
  17.         DP[i+1][j] = min(DP[i+1][j], DP[i][j] + A[i+j+1]);
  18.         DP[i][j+1] = min(DP[i][j+1], DP[i][j] + B[i+j+1]);
  19.     }
  20.     cout << DP[N/2][N/2];
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement