HDU6578 2019HDU multi-school training match first 1001 (dp)

HDU6578 2019HDU multi-school training match first 1001 (dp)

Portal: http://acm.hdu.edu.cn/showproblem.php?pid=6578

Meaning of the questions:

N you need to fill empty, there are m constraints, limits each interval [l, r] of the number of different points for the x, n ask you fill out this empty and satisfies limitations number of programs

answer:

Defined \ (dp [i] [j ] [k] [t] \) represents the t fill out before and after the interval positions, the last position of {0,1,2,3} appear as four numbers i, program number j, k, t of

After rolling out the first dimension of the array optimization, we move follows

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];

Of course, this time we ask that all of the range, so we need to remove the unlawful zone

When determining the weight to the left and right end section and the composition x matches to

Code:

#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;
}

Guess you like

Origin www.cnblogs.com/buerdepepeqi/p/11273067.html