标签:htm 51nod return bitset ack contest ret open src
第1行:一个数N,表示序列的长度(1 <= N <= 100000)
第2 - N + 1行:序列中的元素(1 <= a[i] <= 100000)
输出a的不同子序列的数量Mod 10^9 + 7。
4
1
2
3
2
13
//容易想到是 dp ,dp[i] 以 i 位置为结尾的子序列个数
1 # include <cstdio> 2 # include <cstring> 3 # include <cstdlib> 4 # include <iostream> 5 # include <vector> 6 # include <queue> 7 # include <stack> 8 # include <map> 9 # include <bitset> 10 # include <sstream> 11 # include <set> 12 # include <cmath> 13 # include <algorithm> 14 # pragma comment(linker,"/STACK:102400000,102400000") 15 using namespace std; 16 #define MOD 1000000007 17 #define INF 0x3f3f3f3f 18 #define LL long long 19 #define MX 100005 20 21 int n; 22 int dat[MX]; 23 int zhi[MX]; 24 int pre[MX]; 25 LL sum[MX]; 26 LL dp[MX]; 27 28 int main() 29 { 30 scanf("%d",&n); 31 for (int i=1;i<=n;i++) 32 { 33 scanf("%d",dat+i); 34 pre[i] = zhi[dat[i]]; 35 zhi[dat[i]] = i; 36 } 37 for (int i=1;i<=n;i++) 38 { 39 if (pre[i]==0) 40 dp[i] = (sum[i-1] + 1)%MOD; 41 else 42 dp[i] = (sum[i-1] - sum[pre[i]-1] + MOD)%MOD; 43 sum[i] = (sum[i-1] + dp[i])%MOD; 44 } 45 printf("%lld\n",sum[n]); 46 return 0; 47 }
标签:htm 51nod return bitset ack contest ret open src
原文地址:http://www.cnblogs.com/haoabcd2010/p/7668172.html