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. [ES6] Object.assign (with defaults value object)

    function spinner(target, options = {}){ let defaults = { message: "Please wait", spinningS ...

  2. linux 启动network后报错:device eth0 does not seem to be present, delaying initialization

    问题背景: 在vsphere client中部署ovf模板后启动linux 的network后提示:device eth0 does not seem to be present, delaying ...

  3. shell 判断文件、目录是否存在

    shell判断文件是否存在   1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...

  4. C# winform 加载网页 模拟键盘输入自动接入访问网络

    声明: 本文原创,首发于博客园 http://www.cnblogs.com/EasyInvoice/p/6070563.html 转载请注明出处. 背景: 由于所在办公室网络限制,笔者每天都使用网络 ...

  5. Qt Linux 使用QJson库

    1. 下载 到http://dl.oschina.net/soft/qjson下载库源文件: qjson-0.8.1-1385961227890.zip 解压为:qjson-0.8.1 2. 编译 c ...

  6. ListView 水平滑动 水平和竖直滑动

    效果 Activity public class MainActivity extends Activity {     @Override     protected void onCreate(B ...

  7. SVN Git 设置忽略目录 大全

    eclipse中SVN设置 用svn控制版本,svn本身是不会识别哪些该传,哪些不该传,这就导致有些关于路径的东西(比如拓展jar的路径)也被上传了,而当别人下载后,那个路径对于这个人可能完全不存在, ...

  8. poj 3671 Dining Cows (Dp)

    /* 一开始并没有想出On的正解 后来发现题解的思路也是十分的巧妙的 还是没能把握住题目的 只有1 2这两个数的条件 dp还带练练啊 ... */ #include<iostream> # ...

  9. CSS3 之动画及兼容性调优

    由于CSS3动画对低版本的浏览器的支持效果并不是很好,特别是IE9及以下版本,更是无法支持. 所以有时候一些简单的动画效果,还只是用js代码来实现,但是效率偏低,而且效果有些偏生硬,不够顺滑. 毕竟用 ...

  10. MySQL性能调优与架构设计读书笔记

    可扩展性设计之数据切分 14.2 数据的垂直切分 如何切分,切分到什么样的程度,是一个比较考验人的难题.只能在实际的应用场景中通过平衡各方面的成本和利益,才能分析出一个真正适合自己的拆分方案. 14. ...