Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define INF 999999999999
- #define Size 10005
- struct Pilot{
- long long cap;
- long long ast;
- };
- Pilot A[Size];
- long long DP[Size][5005];
- int N;
- long long call(int cur,int cnt){
- if(cnt - (N-cur) > 0) return INF;
- if(cur == N){
- if(cnt == 0) return 0;
- return INF;
- }
- if(DP[cur][cnt] != -1) return DP[cur][cnt];
- long long res = INF;
- if(cnt > 0){
- long long r1 = call(cur+1,cnt+1) + A[cur].ast;
- long long r2 = call(cur+1,cnt-1) + A[cur].cap;
- res = min(r1,r2);
- }else{
- res = call(cur+1,cnt+1) + A[cur].ast;
- }
- return DP[cur][cnt] = res;
- }
- int main() {
- scanf("%d",&N);
- for(int i = 0;i<N;i++){
- scanf("%lld %lld",&A[i].cap,&A[i].ast);
- }
- memset(DP,-1,sizeof(DP));
- long long res = call(0,0);
- printf("%lld\n",res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment