A. New Year Transportation
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output

New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.

So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer iwhere 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.

Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.

The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

Output

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

Sample test(s)
Input
8 4
1 2 1 2 1 2 1
Output
YES
Input
8 5
1 2 1 2 1 1 1
Output
NO
Note

In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.

In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.

其实是好sb的一道题

因为每个点都只能往右走而且目标唯一,所以怎么搞都行啊

我傻傻的写了爆搜

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
bool mrk[100010];
int a[100010];
int n,m;
inline void dfs(int x)
{
mrk[x]=1;
if (!mrk[x+a[x]])dfs(x+a[x]);
}
int main()
{
n=read();m=read();
for(int i=1;i<n;i++)a[i]=read();
dfs(1);
if (mrk[m]) printf("YES");
else printf("NO");
}

cf500A New Year Transportation的更多相关文章

  1. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  2. 【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)

    Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s repr ...

  3. Heavy Transportation(最短路 + dp)

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  4. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  5. poj 1797 Heavy Transportation(最短路径Dijkdtra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 26968   Accepted: ...

  6. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  7. uva301 - Transportation

      Transportation Ruratania is just entering capitalism and is establishing new enterprising activiti ...

  8. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  9. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

随机推荐

  1. 生成 JSON 数据

    //build an info object and convert to json NSDictionary* info = [NSDictionary dictionaryWithObjectsA ...

  2. MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)

    MySQL主从复制(Master-Slave)即同步与读写分离(MySQL-Proxy)即集群

  3. 使用MySQL的LAST_INSERT_ID--转

    LAST_INSERT_ID 自动返回最后一个 INSERT 或 UPDATE 操作为 AUTO_INCREMENT 列设置的第一个发生的值. 参考这里 The ID that was generat ...

  4. SDWebImage 图片缓存机制

    SDWebImage与iOS系统自带的缓存相比,优势是什么? 从iOS5开始,iOS NSURLCache对于原生得HTTP Response做内存和磁盘缓存.每一次缓存命中(缓存命中就是说内存或者磁 ...

  5. HTTP知识点总结

    参考: HTTP协议详解:http://blog.csdn.net/gueter/article/details/1524447 图解HTTP学习笔记——简单的HTTP协议:http://networ ...

  6. 配置Ssh免密码登录

    配置Ssh免密码登录 一个master节点,两个client节点(client1.client2) 1.所有节点创建hadoop用户,并设置密码 以root账号登录: useradd hadoop p ...

  7. sass笔记-3|Sass基础语法之样式复用和保持简洁

    上一篇详述了Sass如何嵌套.导入和注释这3个基本方式来保持条理性和可读性,这一篇更进一步地阐述sass保持样式复用和简洁的方式--混合器和选择器继承--这两种方式都能复用样式,使用它们也不难,但一定 ...

  8. https加密

    对称加密  客户端和服务器使用同一把钥匙,加密算法公开 非对称加密  不同钥匙,公钥加密的私钥可以打开 私钥加密的公钥可以打开 HTTPS关键: 1. 要传输的业务数据,使用对称加密. 客户端生成私钥 ...

  9. Nagios设置只监控不报警

    设置全部监控项都开启邮件报警: vim /usr/local/nagios/etc/nagios.cfg 设置 enable_notifications=1    1为开启,0为关闭     如个别监 ...

  10. Ps 美白磨皮【1】

      方法一:去色加图层模式法 打开需要编辑的图片,按Ctrl+J复制新的图层1. 点击菜单栏“图像”-“调整”-“去色”,如下图所示. 将图层面板的混合模式更改为“滤色”,如下图4所示. 最后的显示效 ...