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\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pri3(x,y,z) printf("%d %d %d\n",x,y,z)
#define prl(x) printf("%lld\n",x)
#define prl2(x,y) printf("%lld %lld\n",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld\n",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);
}

upc组队赛14 Evolution Game【dp】的更多相关文章

  1. upc组队赛14 As rich as Crassus【扩展中国剩余定理】

    As rich as Crassus 题目链接 题目描述 Crassus, the richest man in the world, invested some of his money with ...

  2. upc组队赛14 Floating-Point Hazard【求导】

    Floating-Point Hazard 题目描述 Given the value of low, high you will have to find the value of the follo ...

  3. upc组队赛14 Communication【并查集+floyd /Tarjan】

    Communication 题目描述 The Ministry of Communication has an extremely wonderful message system, designed ...

  4. upc组队赛14 Bus stop【签到水】

    Bus Stop 题目描述 In a rural village in Thailand, there is a long, straight, road with houses scattered ...

  5. upc组队赛1 不存在的泳池【GCD】

    不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...

  6. upc组队赛15 Made In Heaven【第K短路 A*】

    Made In Heaven 题目描述 One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with ...

  7. upc组队赛6 Progressive Scramble【模拟】

    Progressive Scramble 题目描述 You are a member of a naive spy agency. For secure communication,members o ...

  8. upc组队赛6 Canonical Coin Systems【完全背包+贪心】

    Canonical Coin Systems 题目描述 A coin system S is a finite (nonempty) set of distinct positive integers ...

  9. upc组队赛3 Chaarshanbegaan at Cafebazaar

    Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...

随机推荐

  1. mac 上查看python3的各种安装路径

    1.mac chromedriver的安装目录:/usr/local/bin 2.mac htmltestrunner的存放目录:命令行下 import sys sys.path/Library/Fr ...

  2. win7系统 无线路由关闭了ssid广播 我手动设置了SSID和密码仍然连接不上

    http://zhidao.baidu.com/link?url=KwDGWPc67avpj2OUPg5UqvtqE_80R80P3xzhNIRI1_X5WnSLG7PLEpybb4TnzDAYAB6 ...

  3. drf:筛选,序列化

    1.基础 restful规范: - url:一般用名词 http://www.baidu.com/article (面向资源编程) - 根据请求方式的不同做不同操作:get,post,put,dele ...

  4. Java并发AtomicReference类

    java.util.concurrent.atomic.AtomicReference类提供了可以原子读取和写入的底层对象引用的操作,还包含高级原子操作. AtomicReference支持对底层对象 ...

  5. Cocos2d-x中使用的数据容器类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 在计算机的数据结构中,有着数组,链表,堆栈,队列,树,图,哈希表等一些结构.在面向对象的语言中,这些结构被封装成了特定的类,而这些类就是容 ...

  6. java的实用类

    1)   Random类 用于生成随机数字,所有生成的数字,都是等概率的. nextInt():生成的值介于int的所有取值范围(-231 ~ 231-1) nextInt(int value):生成 ...

  7. [CF895E] Eyes Closed(线段树,期望)

    Desctiption 传送门:Portal 大致题意: 给你一个序列, 支持两种操作: 1 l1 r1 l2 y2 在\([l1, r1]\)随机选择一个数a, \([l2, r2]\) 内随机选择 ...

  8. 插件化框架解读之Class文件与Dex文件的结构(一)

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 Class文件 Class文件是Java虚拟机定义并被其所识别的 ...

  9. C++中类的静态成员变量

    1,成员变量的回顾: 1,通过对象名能够访问 public 成员变量: 2,每个对象的成员变量都是专属的: 3,成员变量不能在对象之间共享: 1,在做程序设计中,成员变量一般是私有的.至少不是公有的: ...

  10. 在线px转换rem工具

    今天推荐一个在线工具,在线px转换rem工具 只要输入1rem = 多少px即可在线转换 和cssrem插件差不多的功能   rem在线转换工具: http://www.ofmonkey.com/fr ...