标签:clu ++ 文件 iostream cin logs out ace cpp
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cstring> using namespace std; int lc[100001]; int cs,begin,end,tot=-2; void dfs(int now,int foot) { if(now==end) { tot=foot; return; } else if(now+lc[now]<=cs) { dfs(now+lc[now],foot+1); } if(now-lc[now]>0) { dfs(now-lc[now],foot+1); } else return; } int main() { cin>>cs>>begin>>end; for(int i=1;i<=cs;i++) { cin>>lc[i]; } dfs(begin,0); if(tot!=-2)cout<<tot; else cout<<-1; return 0; }
标签:clu ++ 文件 iostream cin logs out ace cpp
原文地址:http://www.cnblogs.com/sssy/p/6636800.html