0
点赞
收藏
分享

微信扫一扫

子序列个数 51Nod - 1202

​​https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1202​​

dp[i]代表以i结尾的不同子序列的数量 每次加一个数 就看加到从1到100000之后产生会多少不同子序列

肯定不会有重复 首先不同结尾的子序列加上当前数后还是不同 而同结尾的子序列内保留的就是不同的数量 再加个数还是不同的 递归的考

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e5+10;

ll dp[maxn];
int ary[maxn];
int n;

int main()
{
ll ans,tmp;
int i;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&ary[i]);
ans=0;
for(i=1;i<=n;i++)
{
tmp=(ans+1)%mod;
ans=(ans+(tmp-dp[ary[i]])+mod)%mod;
dp[ary[i]]=tmp;
}
printf("%lld\n",ans);
return 0;
}

 


举报

相关推荐

0 条评论