hdu6078[优化递推过程] 2017多校4

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu6078[优化递推过程] 2017多校4相关的知识,希望对你有一定的参考价值。

/*hdu6078[优化递推过程] 2017多校4*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 998244353LL;
int T, m, n, a[2005], b[2005];
LL sum[2005][3], dp[2005][3];
void solve() {
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        LL up = 1, down = 0;
        for (int j = 1; j <= m; j++) {
            dp[j][0] = dp[j][1] = 0;
            if (b[j] == a[i]) {
                dp[j][0] = up;
                dp[j][1] = down;
                ans = (ans + up + down) % MOD;
            }
            else if (b[j] > a[i]) {
                up = (up + sum[j][1]) % MOD;
            }
            else down = (down + sum[j][0]) % MOD;
            cout<<"j: "<<j<<" up: "<<up<<" down: "<<down<<endl;
        }
        /*for (int j = 1; j <= m; j++) {
            printf("dp[%d][%d][%d]=%lld, dp[%d][%d][%d]=%lld\n", i, j, 0, dp[j][0], i, j, 1, dp[j][1]);
        }*/
        for (int j = 1; j <= m; j++) {
            sum[j][0] = (sum[j][0] + dp[j][0]) % MOD;
            sum[j][1] = (sum[j][1] + dp[j][1]) % MOD;
            //printf("sum[%d][0]=%lld, sum[%d][1]=%lld\n", j, sum[j][0], j, sum[j][1]);
        }
    }
    printf("%lld\n", ans);
}
int main() {
    scanf("%d", &T);
    while (T--) {
        memset(sum, 0, sizeof(sum));
        memset(dp, 0, sizeof(dp));
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }
        for (int i = 1; i <= m; i++) {
            scanf("%d", &b[i]);
        }
        solve();
    }
    return 0;
}

 

以上是关于hdu6078[优化递推过程] 2017多校4的主要内容,如果未能解决你的问题,请参考以下文章

HDU 5863 cjj's string game ( 16年多校10 G 题矩阵快速幂优化线性递推DP )

2021牛客暑期多校训练营4 B.Sample Game(期望平方递推)

hdu6074[并查集+LCA+思维] 2017多校4

HDU 6395(2018多校第7场1010)Sequence

2017多校Round4(hdu6067~hdu6079)

2017多校第9场 HDU 6166 Senior Pan 堆优化Dij