http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3862&konwledgeId=42
#include <bits/stdc++.h> using namespace std; #define maxn 100009 const int MOD = 1e9 + 7; int main() { int n; int a[maxn]; int dp[maxn]; int cnt[11]; while (~scanf("%d",&n)) { memset(a,0,sizeof(a)); memset(dp,0,sizeof(dp)); for (int i = 1;i<=n;i++) { scanf("%d",&a[i]); } dp[0] = 1; for (int i = 1;i<=n;i++) { memset(cnt,0,sizeof(cnt)); for (int j = 0;j<i;j++) { cnt[a[i-j]]++; if (cnt[a[i-j]] > 1) { break; } dp[i] = (dp[i] + dp[i-j-1])%MOD; } } printf("%d\n",dp[n]); } return 0; }
时间: 2024-10-11 22:19:39