当前位置: 首页 > news >正文

做图片推广的网站宁波超值关键词优化

做图片推广的网站,宁波超值关键词优化,自己想做个网站 费用,做app挣钱还是网站题意#xff1a; 起点为1#xff0c;终点为n1#xff0c;对应第i个各点#xff0c;如果我奇数次到达i点#xff0c;那么下一步走到a【i】的位子#xff0c;如果是偶数次到达#xff0c;那么下一步走到i1的位子。 问从1走到n1一共需要走多少步#xff1f;结果对1e97取模…题意 起点为1终点为n1对应第i个各点如果我奇数次到达i点那么下一步走到a【i】的位子如果是偶数次到达那么下一步走到i1的位子。 问从1走到n1一共需要走多少步结果对1e97取模。 题目 One day, little Vasya found himself in a maze consisting of (n  1) rooms, numbered from 1 to (n  1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n  1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let’s consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i  1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. Let’s assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n  1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109  7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 分析 1.定义状态dp[x][y]为从x走到y需要走多少次。 2.如果我们要到达某个点y则要到达y-1的点第一次到达y-1按照题目要求奇数次到达y-1点会到达s【y-1】所以第二次到达y-1,需从s【y-1】到达y-1故推出公式 dp【x】【y】dp【x】【y-1】【s【y-1】】【y-1】1 AC代码 #includestdio.h #includestring.h #includealgorithm using namespace std; const int M1e310; const int mod1e97; int dp[M][M],s[M];//设定dp【i】【j】表示从i走到j一共需要多少步。 int n; void dfs(int x,int y) {if(xy){dp[x][y]1;return ;}if(dp[x][y])return ;/**如果要到达y有两种情况第一次到达y-1回到s[i-1],在偶数次到达y-1时可直接到达y*/dfs(x,y-1);dfs(s[y-1],y-1);///考虑到s【i】i那么要想到i1这个格点去那么一定是从第i个格点走过去的。所以推出普遍公式dp[x][y]dp[x][y-1]dp[s[y-1]][y-1]1;/**那么x--y需要先第一次从x--y-1由规则到达【y-1】再从是【y-1】-y-1*/dp[x][y]%mod; } int main() {while(~scanf(%d,n)){memset(dp,0,sizeof(dp));for(int i1; in; i)scanf(%d,s[i]);dfs(1,n1);printf(%d\n,dp[1][n1]-1);}return 0; }
http://wiki.neutronadmin.com/news/187093/

相关文章:

  • 应聘网站开发题目有趣的网站名
  • phpstudy2016快速搭建网站兰州网站推广建设公司
  • 公司网站建设请示新手做电商如何起步
  • 河北做网站公司那家好投资加盟项目
  • 选择做印象绍兴网站的原因济南seo关键词排名工具
  • 哪个网站做清洁的活多wordpress 离线更新
  • 做公司网站哪家 上海电商网站设计系列
  • 东莞做网站 9353百度外链查询工具
  • 疑问句做网站标题建站平台企业排名
  • 智能建站系统cms淘宝运营培训
  • 网站开发的工作职责专业沈阳网站制作
  • 做外贸一般上什么网站代理平台推荐
  • 哈尔滨建工建设集团网站运营seo实训总结
  • 与别人相比自己网站建设优势做网站的接口是意思
  • 南皮 网站服务器维护公告
  • jq动画效果网站重庆哪些网站推广公司
  • 挂网站需要什么服务器网站404怎么做视频教程
  • 蓝色系网站首页学做视频的网站有哪些内容
  • 可以自己做课程的网站东营百姓网免费发布信息网
  • 企业网站排名运营西安网站托管维护
  • 东莞网站建站推广做网站公众号要多少钱
  • 河北住房和城乡建设厅官方网站新河seo怎么做整站排名
  • 南通市住房和建设局网站好用的免费crm
  • 怎么查看网站哪个公司做的docker wordpress v
  • 高校网站建设申请怎么写wordpress文章链接设置
  • 国网北京电力建设研究院网站珠海网站制作渠道
  • 简述建设一个网站的步骤在线电影视频wordpress主题
  • 聊城网站推广手机上可以制作图片的软件
  • 网站开发 php 实例教程seo外包方案
  • 自己买台服务器做网站贵美商城网站的首页怎么做代码