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. 论文摘抄 - FlumeJava

    本摘抄不保证论文完整性和理解准确性  原始的MapReduce.分Map,Shuffle,Reduce. Map里包含shards. Shuffle理解为groupByKey的事情.Reduce里包含 ...

  2. win7 无线网络无法启动

    开始菜单-运行输入services.msc然后确定!找到WLAN Autoconfig这一项,启动此项服务,一切就OK了

  3. jquery中prop()方法和attr()方法的区别(转)

    jquery1.6中新加了一个方法prop(),一直没用过它,官方解释只有一句话:获取在匹配的元素集中的第一个元素的属性值. 官方例举的例子感觉和attr()差不多,也不知道有什么区别,既然有了pro ...

  4. 对不起,说句粗话——这个太屌了,windows1.0安装程序(附下载)

    今天逛一个软件论坛发现的,仅仅有几百K.遥想当今我刚接触windows的版本号是3.1,当时记得非常清楚哦,进入windows要从dos命令行进入.如今一转眼,变成进入伪dos是执行栏里敲cmd了.唉 ...

  5. 通过yum升级CentOS/RHEL最小化安装

    1.如果你有安装CentOS / RHEL最小服务器安装,您可能有很多麻烦没有安装包 2.有一种方法来安装所有的包,需要一个基本的服务器,使用yum groupinstall命令 3.从最小的安装基本 ...

  6. MySql中的时间类型datetime,timestamp,date,year比较

    MySQL日期类型.日期格式.存储空间.日期范围比较.日期类型        存储空间       日期格式                 日期范围------------ ---------   ...

  7. Entity Framework 新增实体,新增抽象实体

    抽象实体不能new 抽象类:人,实体类:学生 人 p_人= new 学生();   添加数据,学生和人都添加 抽象类可以提供一个抽象的方法,但是并没有实现,类似接口,但又不同于接口.子类继承父类时必须 ...

  8. PHP 杂项 函数

    安装 杂项函数是 PHP 核心的组成部分.无需安装即可使用这些函数. Runtime 配置 杂项函数的行为受 php.ini 文件中的设置的影响. 杂项配置选项: 名称 默认 描述 可更改 ignor ...

  9. MyEclipse导入Maven项目报错 Plugin execution not covered by lifecycle configuration:

    web项目使用到mybatis,需要使用mybatis的自动生成代码插件,配置build部分如下: <build> <pluginManagement></pluginM ...

  10. jquery的节点查询

    jQuery.parent(expr)           //找父元素 jQuery.parents(expr)          //找到所有祖先元素,不限于父元素 jQuery.children ...