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