Dmaxiya

cf 1051 Div.2 D1. Inversion Graph Coloring (Easy Version)

Sep 20th, 2025 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 300 + 100;
  6. const LL MOD = 1000000007;
  7. int T, n;
  8. LL ans;
  9. int a[maxn];
  10. LL dp[maxn][maxn][maxn];
  11.  
  12. int main(){
  13. #ifdef ExRoc
  14.     freopen("test.txt", "r", stdin);
  15. #endif // ExRoc
  16.     ios::sync_with_stdio(false);
  17.  
  18.     cin >> T;
  19.     while (T--) {
  20.         cin >> n;
  21.         for (int i = 1; i <= n; ++i) {
  22.             cin >> a[i];
  23.         }
  24.         dp[0][0][0] = 1;
  25.         for (int i = 1; i <= n; ++i) {
  26.             memcpy(dp[i], dp[i - 1], sizeof(dp[i]));
  27.             for (int sec = 0; sec < a[i]; ++sec) {
  28.                 for (int mx = sec; mx <= a[i]; ++mx) {
  29.                     dp[i][a[i]][sec] = (dp[i][a[i]][sec] + dp[i - 1][mx][sec]) % MOD;
  30.                 }
  31.             }
  32.             for (int mx = a[i] + 1; mx <= n; ++mx) {
  33.                 for (int sec = 0; sec <= a[i]; ++sec) {
  34.                     dp[i][mx][a[i]] = (dp[i][mx][a[i]] + dp[i - 1][mx][sec]) % MOD;
  35.                 }
  36.             }
  37.         }
  38.         ans = 0;
  39.         for (int i = 0; i <= n; ++i) {
  40.             for (int j = 0; j <= n; ++j) {
  41.                 ans = (ans + dp[n][i][j]) % MOD;
  42.             }
  43.         }
  44.         cout << ans << endl;
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment