Add a bunch of other problems.

This commit is contained in:
2025-12-15 13:40:39 -03:00
parent 97ebdbf890
commit c4acd23d19
172 changed files with 25644 additions and 79 deletions

View File

@@ -75,53 +75,67 @@ auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
return is;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
const ll mod = 1e9 + 7;
int n;
cin >> n;
vi a(n);
cin >> a;
vvvl dp(n + 1, vvl(n + 1, vl(n + 1)));
dp[0][0][0] = 1;
nrep(i, 1, n + 1) {
int cur = a[i - 1];
dp[i] = dp[i - 1];
rep(j, n + 1) {
rep(k, min(cur, j) + 1) {
if (cur >= j) {
dp[i][cur][k] += dp[i - 1][j][k];
dp[i][cur][k] %= mod;
continue;
}
dp[i][j][cur] += dp[i - 1][j][k];
dp[i][j][cur] %= mod;
}
}
}
ll ans = 0;
rep(i, n + 1) {
rep(j, n + 1) {
ans = (ans + dp[n][i][j]) % mod;
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
cin >> t;
(TEST && cin >> t) || (t = 1);
while (t--) {
int n;
cin >> n;
vi a(n);
cin >> a;
ll mod = 1e9 + 7;
vvvl memo(n, vvl(n + 1, vl(n + 1, -1)));
function<ll(int, int, int)> dp = [&](int i, int maximal, int mp) {
if (i >= n) {
return 1LL;
}
ll &ans = memo[i][maximal][mp];
if (ans != -1) {
return ans;
}
ans = dp(i + 1, maximal, mp);
if (a[i] < maximal && a[i] < mp) {
return ans;
}
if (a[i] >= maximal) {
ans += dp(i + 1, a[i], mp);
ans %= mod;
}
if (a[i] < maximal) {
ans += dp(i + 1, maximal, max(mp, a[i]));
ans %= mod;
}
return ans;
};
cout << dp(0, 0, 0) << '\n';
solve();
}
}