看了 dp 方程之后应该是妙懂
每次 加入一个数,×2 然后剪掉重复的; 重复的个数 维前面那个数,,,,,
1 #include<iostream> 2 #include<stdio.h> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #define mod 1000000007 7 using namespace std; 8 9 long long dp[1123456],pre[1123456]; 10 int main( ) 11 { 12 int N; 13 while( scanf("%d",&N) != EOF ) 14 { 15 memset( pre,0,sizeof( pre) ); 16 memset( dp,0,sizeof(dp) ); 17 int now; scanf("%d",&now); dp[1] = 1; pre[now] = 1; 18 for( int i = 2; i <= N; i++ ) 19 { 20 int now; scanf("%d",&now); 21 dp[i] = (((dp[i-1]*2)%mod) - dp[pre[now]-1]); 22 if( !pre[now] )dp[i] += 1; 23 pre[now] = i; 24 dp[i] += mod; 25 dp[i] %= mod; 26 } 27 printf("%lld ",dp[N]); 28 } 29 return 0; 30 }