zoukankan      html  css  js  c++  java
  • 【玲珑杯 round#18 B】图论你先敲完模板

    Link:http://www.ifrog.cc/acm/problem/1146

    Description

    Solution

    设f[i]表示在第i个点休息的话最少需要的体力值;
    f[i]=min(f[j]+2x[i]x[j]+a)
    (j<i)
    答案为f[n]
    注意,如果每个点都休息的话;
    总的花费是不会超过260
    所以,当x[i]-x[j]>60, 直接break
    然后把x值相同的,直接去掉就好,(肯定不用停,因为停了又不会前进);
    (以防所有坐标都一样,卡时间)

    NumberOf WA

    3

    Reviw

    这是对动态规划的一种优化.思想要掌握!
    一开始的时候,没往动态规划那块想。

    Code

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 1e5;
    
    int T,n,x[N+100];
    LL t[100],f[N+100],a;
    
    int main(){
        //Open();
        //Close();
        t[0] = 1;
        rep1(i,1,60)
            t[i] = t[i-1]*2;
        scanf("%d",&T);
        while (T--){
            scanf("%d%lld",&n,&a);
            rep1(i,1,n) scanf("%d",&x[i]);
            int nn = 1;
            rep1(i,2,n)
                if (x[i]!=x[i-1])
                    x[++nn] = x[i];
            n = nn;
            rep1(i,1,n) f[i] = -1;
            f[1] = 0;
            rep1(i,2,n){
                rep2(j,i-1,1){
                    if (x[i]-x[j]>60) break;
                    if (f[i]==-1)
                        f[i] = f[j]+a+t[x[i]-x[j]];
                    else
                        f[i] = min(f[i],f[j]+a+t[x[i]-x[j]]);
                }
            }
            printf("%lld
    ",f[n]);
        }
        return 0;
    }
  • 相关阅读:
    GridView Footer页脚统计实现多行
    Windows cmd 启动 tomcat 中文乱码问题
    git
    CentOS 的 dnf 命令
    不知道是否是wcf 的一个bug
    图像卷积与滤波的一些知识点
    Phaser开源2d引擎 javascript/html5游戏框架
    关于Ldoc
    自写vim插件ldoc.vim,提供智能的lua注释代码补全
    svn diff 使用 vimdiff 作为比较差异工具
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626185.html
Copyright © 2011-2022 走看看