HDU6578 2019HDUマルチ学校の練習試合最初の1001(DP)

HDU6578 2019HDUマルチ学校の練習試合最初の1001(DP)

ポータル:http://acm.hdu.edu.cn/showproblem.php?pid=6578

質問の意味:

Nあなたはこの空を満たす制限を記入尋ねるN、xの異なる点の数の各区間[L、R]を制限し、m個の制約がある、空で充填する必要がありますプログラムの数

ソリューション:

定義\(DP [I] [J ] [K] [t]が\) 私は、4つの数字として、tは前記入表し、間隔位置の後、{0,1,2,3}の最後の位置が表示されプログラム番号j、kの、のトン

配列の最適化の最初の次元を展開した後、我々は次の移動します

DP [P] [j] [k]は[T] + = DP [P ^ 1]〜[J] [K] [T]。
DP [P] [I - 1] [K] [T] + = DP [P ^ 1]〜[J] [K] [T]。
DP [P] [I - 1] [J] [T] + = DP [P ^ 1]〜[J] [K] [T]。
DP [P] [I - 1] [J] [K] + = DP [P ^ 1]〜[J] [K] [T]。

もちろん、今回は範囲のすべてのことを聞いて、私たちは、違法なゾーンを削除する必要があります

左右の端部及び組成xに重みを決定するときに一致

コード:

#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 3e2 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const double Pi = acos(-1);
LL gcd(LL a, LL b) {
    return b ? gcd(b, a % b) : a;
}
LL lcm(LL a, LL b) {
    return a / gcd(a, b) * b;
}
double dpow(double a, LL b) {
    double ans = 1.0;
    while(b) {
        if(b % 2)ans = ans * a;
        a = a * a;
        b /= 2;
    } return ans;
}
LL quick_pow(LL x, LL y) {
    LL ans = 1;
    while(y) {
        if(y & 1) {
            ans = ans * x % mod;
        } x = x * x % mod;
        y >>= 1;
    } return ans;
}
vector<pii> vec[maxn];
int dp[2][maxn][maxn][maxn];
void MOD(int &x) {
    if(x >= mod) x -= mod;
}
int main() {
#ifndef ONLINE_JUDGE
    FIN
#endif
    int T;
    scanf("%d", &T);
    while(T--) {
        int n, m;
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; i++) {
            vec[i].clear();
        }
        for(int i = 1; i <= m; i++) {
            int l, r, x;
            scanf("%d%d%d", &l, &r, &x);
            vec[r].push_back(make_pair(l, x));
        }
        dp[0][0][0][0] = 1;

        for(int i = 1, p = 1; i <= n; i++, p ^= 1) {
            for(int j = 0; j <= i; j++) {
                for(int k = 0; k <= j; k++) {
                    for(int t = 0; t <= k; t++) {
                        dp[p][j][k][t] = 0;
                    }
                }
            }
            for(int j = 0; j < i; j++) {
                for(int k = 0; k <= j; k++) {
                    for(int t = 0; t <= k; t++) {
                        MOD(dp[p][j][k][t] += dp[p ^ 1][j][k][t]);
                        MOD(dp[p][i - 1][k][t] += dp[p ^ 1][j][k][t]);
                        MOD(dp[p][i - 1][j][t] += dp[p ^ 1][j][k][t]);
                        MOD(dp[p][i - 1][j][k] += dp[p ^ 1][j][k][t]);
                    }
                }
            }
            for(int j = 0; j < i; j++) {
                for(int k = 0; k <= j; k++) {
                    for(int t = 0; t <= k; t++) {
                        for (auto tmp : vec[i]) {
                            //不合法区间,清零
                            if (1 + (j >= tmp.first) + (k >= tmp.first) + (t >= tmp.first) != tmp.second) {
                                dp[p][j][k][t] = 0;
                            }
                        }
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 0, p = n & 1; i < n; i ++)
            for (int j = 0; j <= i; j ++)
                for (int k = 0; k <= j; k ++)
                    MOD(ans += dp[p][i][j][k]);
        printf("%d\n", ans);

    }
    return 0;
}

おすすめ

転載: www.cnblogs.com/buerdepepeqi/p/11273067.html
おすすめ