Tarango

Untitled

Nov 4th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define INF 999999999999
  4. #define Size 10005
  5.  
  6. struct Pilot{
  7.     long long cap;
  8.     long long ast;
  9. };
  10.  
  11. Pilot A[Size];
  12. long long DP[Size][5005];
  13. int N;
  14.  
  15. long long call(int cur,int cnt){
  16.     if(cnt - (N-cur) > 0) return INF;
  17.     if(cur == N){
  18.         if(cnt == 0) return 0;
  19.         return INF;
  20.     }
  21.     if(DP[cur][cnt] != -1) return DP[cur][cnt];
  22.     long long res = INF;
  23.     if(cnt > 0){
  24.         long long r1 = call(cur+1,cnt+1) + A[cur].ast;
  25.         long long r2 = call(cur+1,cnt-1) + A[cur].cap;
  26.         res = min(r1,r2);
  27.     }else{
  28.         res = call(cur+1,cnt+1) + A[cur].ast;
  29.     }
  30.     return DP[cur][cnt] = res;
  31. }
  32.  
  33. int main() {
  34.     scanf("%d",&N);
  35.     for(int i = 0;i<N;i++){
  36.         scanf("%lld %lld",&A[i].cap,&A[i].ast);
  37.     }
  38.     memset(DP,-1,sizeof(DP));
  39.     long long res = call(0,0);
  40.     printf("%lld\n",res);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment