Tuesday, 5 January 2016

UVa 10337 - Flight Planner

//\\__ hr1212 __//\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;

#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007

int n,m,a[12][100005],dp[100005][12];

int solve(int i,int alt){
    if(i==m && alt==0)
        return 0;
    if(i<0 || i>=m || alt<0 || alt>9)
        return 1e9;
    if(dp[i][alt]!=-1)
        return dp[i][alt];
    return dp[i][alt]=min(min(solve(i+1,alt-1)+20,solve(i+1,alt+1)+60),solve(i+1,alt)+30)-a[alt][i];
}

int main(){
    int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
    ll ans=0;string p;

    si(t);
    while(t--){
        si(n);
        m=n/100;
        clr(dp,-1);
        rf(i,9,0){
            f(j,0,m){
                si(a[i][j]);
            }
        }
        pi(solve(0,0));
    }

    return 0;
}

No comments:

Post a Comment