Codeforces 407B Long Path

Source: Internet
Author: User

Test instructions: Some points in a column, only access I even several times to access i+1, otherwise access pi

Problem-Solving ideas: We know that when we visit I, all the points in front of I must be even, so access I after access to i+1 steps dp[i] = Dp[pi] + dp[pi+1]+.....dp[i-1] + 2;

Problem Solving Code:

1 //File name:407b.cpp2 //Author:darkdream3 //Created time:2015 March 07 Saturday 11:36 30 Seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - #defineM 1000000007 - using namespacestd; -LL dp[1005]; - intMain () { in     intN; -scanf"%d",&n); to     inttmp; +dp[1] =2; -scanf"%d",&tmp); theLL sum =1;  *      for(inti =2; I <= N;i + +) $     {Panax Notoginsengscanf"%d",&tmp); -Dp[i] =2;  the        for(intj = tmp; J < I; J + +) +       { ADp[i] = (Dp[i] +dp[j])%M; the       } +sum = (sum +dp[i])%M; -     } $printf"%i64d\n", (sum+1)%M); $ return 0; -}
View Code

Codeforces 407B Long Path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.