题目链接

感觉这道题我看了很多天,胡思乱想啊,一开始觉得记忆化搜索会可能T啊,,可能出题人的数据卡的好就稳T了的感觉。。后来想了想,好像离散化一下,记一下位置之后再记忆化搜索就应该稳了吧。。(好像直接搜也不会T的,,??)

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <bitset>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define MAXN 1010100
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll __int64
#define INF 0x7fffffff
#define cs(s) freopen(s,"r",stdin)
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
const int maxn=1e5+1;
int dp[maxn][3],ans;
int a[maxn],b[maxn],pos[maxn],n;
int dfs(int now,int sta){
if(now==n)return dp[now][sta]=1;
if(dp[now][sta]!=-1)return dp[now][sta];
if(sta==0){
int cnt=0;
while(pos[a[now]+cnt]<=now&&a[now]+cnt+1<=n)cnt++;
if(pos[a[now]+cnt]<=now)return dp[now][sta]=0;
return dp[now][sta]=dfs(pos[a[now]+cnt],1);
}else {
int cnt=0;
while(pos[a[now]-cnt]<=now&&a[now]-cnt-1>=1)cnt++;
if(pos[a[now]-cnt]<=now)return dp[now][sta]=0;
return dp[now][sta]=dfs(pos[a[now]-cnt],0);
}
}
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];
sort(b+1,b+1+n);
int cnt=unique(b+1,b+1+n)-b-1;
for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+1+cnt,a[i])-b,pos[a[i]]=i;
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;i++)if(dfs(i,0))ans++;
cout<<ans<<endl;
return 0;
}

第二天 ,写了一个非递归的版本。。。快一点,大致都差不多的。

dp[i][0]=dp[pos][1],(a[i]<a[pos],且a[pos]>a[p] {p!=pos且p>i且a[p]<a[i]}。

dp[i][1]=dp[pos][0],(a[i]>a[pos],且a[pos]<a[p] {p!=pos且p>i且a[p]>a[i]}。

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <bitset>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define MAXN 1010100
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll __int64
#define INF 0x7fffffff
#define cs(s) freopen(s,"r",stdin)
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
const int maxn=1e5+1;
int dp[maxn][3],ans;
int a[maxn],b[maxn],pos[maxn],n;
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];
sort(b+1,b+1+n);
int cnt=unique(b+1,b+1+n)-b-1;
for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+1+cnt,a[i])-b,pos[a[i]]=i;
dp[n][0]=dp[n][1]=1;
for(int i=n-1;i>=1;i--){
int cnt=0;
while(pos[a[i]+cnt]<=i&&a[i]+cnt+1<=n)cnt++;
if(pos[a[i]+cnt]<=i)dp[i][1]=0;
else dp[i][1]=dp[pos[a[i]+cnt]][0];
cnt=0;
while(pos[a[i]-cnt]<=i&&a[i]-cnt-1>=1)cnt++;
if(pos[a[i]-cnt]<=i)dp[i][0]=0;
else dp[i][0]=dp[pos[a[i]-cnt]][1];
}
for(int i=1;i<=n;i++)if(dp[i][1]||i==n)ans++;
cout<<ans<<endl;
return 0;
}

EcustOJ P109跳一跳(离散化+dp)的更多相关文章

  1. 【loj6342】跳一跳 期望dp

    题目描述 一个人从 $1$ 开始向 $n$ 跳,在 $i$ 时会等概率跳到 $i,i+1,...,n$ 之一.求从 $1$ 跳到 $n$ 的期望步数. $n\le 10^7$ . 题解 期望dp傻逼题 ...

  2. loj #6342. 跳一跳 期望dp

    令 $f[i]$ 表示已经到达 $i$ 点,为了到大 $n$ 点还期望需要的时间,随便转移一下就行. 由于本题卡空间,要记得开滚动数组. #include <bits/stdc++.h> ...

  3. 挑战App Store,微信通过“跳一跳”秀了一下“小程序”的肌肉

    2017年即将结束的时候,微信放了一个大招.随着最新的微信v6.6.1版本更新,基于小程序的"小游戏"板块正式上线.微信上首发的这款"小游戏"叫"跳一 ...

  4. .NET开发一个微信跳一跳辅助程序

    昨天微信更新了,出现了一个小游戏"跳一跳",玩了一下 赶紧还蛮有意思的 但纯粹是拼手感的,玩了好久,终于搞了个135分拿了个第一名,没想到过一会就被朋友刷下去了,最高的也就200来 ...

  5. C#又能出来装个B了。一步一步微信跳一跳自动外挂

    PS:语言只是载体.思维逻辑才是王道 前天看见了个python的脚本.于是装python.配置环境变量.装pip.折腾了一上午,最终装逼失败. 于是进入博客园,顶部有篇文章吸引了我 .NET开发一个微 ...

  6. 用C#实现微信“跳一跳”小游戏的自动跳跃助手

    一.前言: 前段时间微信更新了新版本后,带来的一款H5小游戏“跳一跳”在各朋友圈里又火了起来,类似以前的“打飞机”游戏,这游戏玩法简单,但加上了积分排名功能后,却成了“装逼”的地方,于是很多人花钱花时 ...

  7. Adb+.net 实现微信跳一跳自动化

    第一次用adb,一开始只是想试试看能不能解析出,没有看网上的现有解析方式. 需要安卓机开启usb 调试+电脑运行.打开跳一跳的界面 点击程序 [开始]按钮即可开始,别的按钮都是调试用的 主要流程是用a ...

  8. 微信跳一跳Python

    微信最新的小程序里面出了个叫“跳一跳”的小游戏,大神们也通过Python实现了自动玩游戏具体代码 如下: Github地址: https://github.com/wangshub/wechat_ju ...

  9. 微信跳一跳辅助自动跳Python

    一.说明 此代码借鉴github一位大神所写,已经做了简化合并处理,如果能成功连上手机并运行,可以实现程序自动玩游戏,刷个1000+的分数轻轻松松 github源码地址 https://github. ...

随机推荐

  1. Jmeter接口自动化

    基本思路: 在excel中维护测试用例,包括访问协议,服务器名或IP,路径,请求的方法,端口号,提交参数,测试结果等,使用CSV Data Set Config读取请求信息并写入测试结果,后期只要维护 ...

  2. TestNg 11. 超时测试

    前沿:多久时间没有响应,就是超时. 代码:用timeOut这个属性,超过规定的时间就是fail,不超过就是success package com.course.testng; import org.t ...

  3. echarts柱状图 渐变色

    效果图:  var xAxisData = []; var data = []; for (var i = 9; i < 16; i++) { xAxisData.push('5月' + i + ...

  4. 简单贪心) Repair the Wall hdu2124

    Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...

  5. Cookie隐藏小广告

    方式一:在close.php页面上设置COOKIE, colse.php页面 <?php setcookie('hide','1'); header('Location: indes.php') ...

  6. nginx根据cookie分流

    转载互联网 nginx根据cookie分流众所周知,nginx可以根据url path进行分流,殊不知对于cookie分流也很强大,同时这也是我上篇提到的小流量实验的基础. 二话不说,先看需求,两台服 ...

  7. kernel(二)源码浅析

    目录 kernel(二)源码浅析 建立工程 启动简析 head.s 入口点 查询处理器 查询机器ID 启动MMU 其他操作 start_kernel 处理命令行 分区 title: kernel(二) ...

  8. Linux网卡调优篇-禁用ipv6与优化socket缓冲区大小

    Linux网卡调优篇-禁用ipv6与优化socket缓冲区大小 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一般在内网环境中,我们几乎是用不到IPV6,因此我们没有必要把多不 ...

  9. TensorFlow tensor张量拼接concat - split & stack - unstack

    TensorFlow提供两种类型的拼接: tf.concat(values, axis, name='concat'):按照指定的已经存在的轴进行拼接 tf.stack(values, axis=0, ...

  10. python第一次周末大作业

    #############################作业############################# 1. 三次登录验证 完成用户登录验证 要求: 1. 系统自动生成4位随机数. ...