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 ",dp[n]); } return 0; }
https://hihocoder.com/problemset/problem/1482
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int dp[100000 + 1000][2][3]; long long Add(int a,int b) { long long ans = (a+b)%MOD; return ans; } void Init() { memset(dp,0,sizeof(dp)); dp[0][0][0] = 1; for (int i = 0;i<100000;i++) { for (int j = 0;j<2;j++) { for (int k = 0;k<3;k++) { dp[i+1][j][0] = Add(dp[i+1][j][0],dp[i][j][k]); if (j != 1) { dp[i+1][j+1][0] = Add(dp[i+1][j+1][0],dp[i][j][k]); } if (k != 2) { dp[i+1][j][k+1] = Add(dp[i+1][j][k+1],dp[i][j][k]); } } } } } int main() { int n; Init(); while (~scanf("%d",&n)) { int ans = 0; for (int i = 0;i<2;i++) { for (int j = 0;j<3;j++) { //printf("%d ",dp[n][i][j]); ans = Add(ans,dp[n][i][j]); } } printf("%d ",ans); } return 0; }