Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 300 + 100;
- const LL MOD = 1000000007;
- int T, n;
- LL ans;
- int a[maxn];
- LL dp[maxn][maxn][maxn];
- int main(){
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- ios::sync_with_stdio(false);
- cin >> T;
- while (T--) {
- cin >> n;
- for (int i = 1; i <= n; ++i) {
- cin >> a[i];
- }
- dp[0][0][0] = 1;
- for (int i = 1; i <= n; ++i) {
- memcpy(dp[i], dp[i - 1], sizeof(dp[i]));
- for (int sec = 0; sec < a[i]; ++sec) {
- for (int mx = sec; mx <= a[i]; ++mx) {
- dp[i][a[i]][sec] = (dp[i][a[i]][sec] + dp[i - 1][mx][sec]) % MOD;
- }
- }
- for (int mx = a[i] + 1; mx <= n; ++mx) {
- for (int sec = 0; sec <= a[i]; ++sec) {
- dp[i][mx][a[i]] = (dp[i][mx][a[i]] + dp[i - 1][mx][sec]) % MOD;
- }
- }
- }
- ans = 0;
- for (int i = 0; i <= n; ++i) {
- for (int j = 0; j <= n; ++j) {
- ans = (ans + dp[n][i][j]) % MOD;
- }
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment