UESTC 1047 Alice's birthday
原题地址:http://acm.uestc.edu.cn/#/problem/show/1047
题意
一条长为n的路,Bob要从一个端点走到另一个端点,途中有m个服务站,每个服务站提供两种服务可供选择
1.瞬间向前前进一个单位的距离
2.使Bob走过一个距离的要花的时间减1
问Bob在每个服务站如何选择可以使自己最快到达路的另一端。
题解
对于方案二,永远是晚选不如早选
所以贪心就好
枚举选择方案二的次数
决策问题:贪心 or DP
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5;
int dist[maxn+5];
LL T[maxn+5];
int main(void)
{
    #ifdef ex
    freopen ("in.txt","r",stdin);
    //freopen ("out.txt","w",stdout);
    #endif
    
    LL n,m,t;
    
    scanf("%lld%lld%lld",&n,&m,&t);
    
    for (int i=1;i<=m;++i)
    {
        scanf("%d",&dist[i]);
    }
    
    T[0]=0;
    LL ans=t*(n-m);
    for (int i=1;i<=m;++i)
    {
        T[i]=T[i-1]+t*(dist[i]-dist[i-1]);
        ans=min(ans,T[i]+(t-1)*(n-dist[i]-(m-i)));
        --t;
        
        if (t==0) break;
    }
    
    printf("%lld\n",ans);
}
posted on 2016-06-07 21:22 zhong_wang 阅读(148) 评论(0) 收藏 举报
 
                    
                     
                    
                 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号 
