zoukankan      html  css  js  c++  java
  • upc组队赛14 Evolution Game【dp】

    Evolution Game

    题目描述

    In the fantasy world of ICPC there are magical beasts. As they grow, these beasts can change form, and every time they do they become more powerful. A beast cannot change form completely arbitrarily though. In each form a beast has n eyes and k horns, and these affect the changes it can make.

    A beast can only change to a form with more horns than it currently has.
    A beast can only change to a form that has a difference of at most w eyes. So, if the beast currently has n eyes it can change to a form with eyes in range [n - w, n + w].

    A beast has one form for every number of eyes between 1 and N, and these forms will also have an associated number of horns. A beast can be born in any form. The question is, how powerful can one of these beasts become? In other words, how many times can a beast change form before it runs out of possibilities?

    输入

    The first line contains two integers, N and w, that indicate, respectively, the maximum eye number, and the maximum eye difference allowed in a change (1 ≤ N ≤ 5000; 0 ≤ w ≤ N).
    The next line contains N integers which represent the number of horns in each form. I.e. the ith number, h(i), is the number of horns the form with i eyes has (1 ≤ h(i) ≤ 1 000 000).

    输出

    For each test case, display one line containing the maximum possible number of changes.

    样例输入

    5 5
    5 3 2 1 4
    

    样例输出

    4
    

    题意

    角从小变大,在眼睛范围w内的进化,问最多能进化几次?

    题解

    一个比较明显的dp,先对角进行排序,从后向前遍历,满足在w范围内的就dp+1

    代码

    #include<iostream>
    #include<cstdio>  //EOF,NULL
    #include<cstring> //memset
    #include<cstdlib> //rand,srand,system,itoa(int),atoi(char[]),atof(),malloc
    #include<limits.h> //INT_MAX
    #include<bitset> // bitset<?> n
    #include<cmath>  //ceil,floor,exp,log(e),log10(10),hypot(sqrt(x^2+y^2)),cbrt(sqrt(x^2+y^2+z^2))
    #include<algorithm> //fill,reverse,next_permutation,__gcd,
    #include<iomanip> //setw(set_min_width),setfill(char),setprecision(n),fixed,
    #include<string>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<utility>
    #include<iterator>
    #include<functional>
    #include<map>
    #include<set>
    using namespace std;
    #define rep(i,a,n) for(int i=a;i<n;i++)
    #define scac(x) scanf("%c",&x)
    #define sca(x) scanf("%d",&x)
    #define sca2(x,y) scanf("%d%d",&x,&y)
    #define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define scl(x) scanf("%lld",&x)
    #define scl2(x,y) scanf("%lld%lld",&x,&y)
    #define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
    #define pri(x) printf("%d
    ",x)
    #define pri2(x,y) printf("%d %d
    ",x,y)
    #define pri3(x,y,z) printf("%d %d %d
    ",x,y,z)
    #define prl(x) printf("%lld
    ",x)
    #define prl2(x,y) printf("%lld %lld
    ",x,y)
    #define prl3(x,y,z) printf("%lld %lld %lld
    ",x,y,z)
    #define ll long long
    #define LL long long
    #define read read()
    #define pb push_back
    #define mp make_pair
    #define P pair<int,int>
    #define PLL pair<ll,ll>
    #define PI acos(1.0)
    #define eps 1e-6
    #define inf 1e17
    #define INF 0x3f3f3f3f
    #define N 5005
    const int maxn = 2000005;
    int n,w;
    
    struct node
    {
      int h,e,dp;
    }a[N];
    bool cmp(node a,node b)
    {
      return a.h < b.h;
    }
    int main()
    {
      sca2(n,w);
      rep(i,1,n+1)
      {
        sca(a[i].h);
        a[i].e = i;
      }
      sort(a+1,a+n+1,cmp);
      int l,r;
      for(int i = n; i >= 1;i--)
      {
        l = a[i].e - w,r = a[i].e + w;
        rep(j,i+1,n+1)
        {
          if(a[j].e >= l && a[j].e <= r && a[j].h > a[i].h)
          {
            a[i].dp = max(a[i].dp,a[j].dp+1);
          }
        }
      }
      int ans = a[1].dp;
      rep(i,2,n+1)
        ans = max(ans,a[i].dp);
      pri(ans);
    }
    
    
    
  • 相关阅读:
    (转)dubbo远程调用细节
    (转)Dubbo扩展点实现细节
    (转)dubbo design
    (转) java中try/catch性能和原理
    mybatis入门基础(九)----逆向工程
    客观评价下软件培训机构
    mybatis入门基础(八)-----查询缓存
    mybatis入门基础(七)----延迟加载
    mybatis入门基础(六)----高级映射(一对一,一对多,多对多)
    为什么我不推荐大家去外包公司
  • 原文地址:https://www.cnblogs.com/llke/p/10806152.html
Copyright © 2011-2022 走看看