zoukankan      html  css  js  c++  java
  • CF505C Mr. Kitayuta, the Treasure Hunter(dp)

    朴素的思路就是二维dp,表示上次跳了几个

    但是这个存不下,又因为题目提示我们第一次一定是D

    因此我们第二维表示上次移动了D+j次,这是因为j只要移动250,就能到达终点,因此可以存下

    但是可能是负数,因此我们使用坐标系平移

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int N=1e5+10;
    int base=250;
    int f[30010][510];
    int a[N];
    int main(){
        ios::sync_with_stdio(false);
        int n,d;
        cin>>n>>d;
        int i,j;
        for(i=1;i<=n;i++){
            int x;
            cin>>x;
            a[x]++;
        }
        memset(f,-0x3f,sizeof f);
        f[d][base]=a[d];
        int ans=0;
        ans=a[d];
        for(i=d+1;i<=30000;i++){
            for(j=0;j<=500;j++){
                int last=i-(d+j-base);
                if(last<0||last>=i)
                    continue;
                for(int k=-1;k<=1;k++){
                    if(j+k>0){
                        f[i][j]=max(f[i][j],f[last][j+k]+a[i]);
                    }
                }
                ans=max(ans,f[i][j]);
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    中序遍历
    二叉树前序遍历
    A Real Stewart
    走遍美国 听写
    2016-12-12——2016-12-16友邻
    英语百日听力
    6.2分鱼问题两种解法
    Bootstrap组件1
    Bootstrap图标及另一个好用图标网站介绍
    Bootstrap全局CSS样式之图片
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/14497951.html
Copyright © 2011-2022 走看看