题目链接

感觉这道题我看了很多天,胡思乱想啊,一开始觉得记忆化搜索会可能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. 安卓手机root

    https://jingyan.baidu.com/article/ca41422ffe6b031eae99ed9a.html

  2. JDBC批处理(Batch)MySQL中的表

    在数据库test里先创建表school,内容如下 向school表中一次增加多行.addBatch,executeBatch import java.sql.Connection; import ja ...

  3. C#语法糖(Csharp Syntactic sugar)

    目录 一.C#语法糖大汇总 1. 经过简化的Property2. 经过两次变异的委托写法3. 集合类的声明4. 集合类各个项的操作5. using == try finally6. 可爱的var7. ...

  4. 字符设备驱动(六)按键poll机制

    title: 字符设备驱动(六)按键poll机制 tags: linux date: 2018-11-23 18:57:40 toc: true --- 字符设备驱动(六)按键poll机制 引入 在字 ...

  5. spring集成Hessian的基本使用方法

    一.什么是RPC RPC全称Remote Procedure Call,中文名叫远程过程调用.RPC是一种远程调用技术,用于不同系统之间的远程相互调用.其在分布式系统中应用十分广泛. 二.什么是Hes ...

  6. 【SSL】WebClient 请求 https 页面出错:未能创建 SSL/TLS 安全通道

    #问题: 当向一个https的url上发送请求,报错:未能创建 SSL/TLS 安全通道: using (WebClient client = new WebClient()) { string ad ...

  7. synchronized 和lock的区别

    synchronized 是什么时候释放? 1.获取锁的线程执行完代码2.线程执行出现异常 synchronized 的缺陷? 1.Lock类可以主动释放锁.2.synchronized 是被动. R ...

  8. [JDK8] Lambda

    本文转载原文http://www.cnblogs.com/jalja/p/7655170.html 一.使用线程 public static void main(String[] args) { // ...

  9. C#实现的系统内存清理

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  10. OPCServer:使用Matrikon OPC Server Simulation

    实验用模拟OPCServer 旧版(50M):Matrikon OPC Server Simulation(v1.5.0.0),百度网盘,密码: mcur 新版(157M):Matrikon OPC ...