NC17065 子序列

题目地址:

https://ac.nowcoder.com/acm/problem/17065

基本思路:

很明显这个题目是一个计数dp但是图片说明 这个式子值很大不好用来比较,但是我们化简一下两边取log就能得到这个式子图片说明,然后就是一个很朴素的计数dp了。设dp[i]表示以第i个元素结尾的所有子序列那么我们能得到转移方程图片说明 那么最后的答案就是图片说明

参考代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 110;
const int mod = 1e9 + 7;
int n,a[maxn],dp[maxn];
bool change(int i,int j){
  double k1 = (double)j * log(a[i]);
  double k2 = (double)i * log(a[j]);
  return k2 < k1;
}
signed main() {
  IO;
  cin >> n;
  rep(i,1,n) cin >> a[i];
  int res = 0;
  for(int i = 1; i <= n ; i++){
    dp[i] = 1;
    for(int j = 1 ; j < i ; j ++) if(change(i,j)){
      dp[i] = (dp[i] + dp[j]) % mod;
    }
    res += dp[i];
    res %= mod;
  }
  cout << res << '\n';
  return 0;
}