[补]2019HDU杭电多校第一场A

Posted non-

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[补]2019HDU杭电多校第一场A相关的知识,希望对你有一定的参考价值。

不要2000,不要1000,只要998,AC带回家

红小豆在此真诚求教更快的方法orz

 

参考:https://www.cnblogs.com/DeaphetS/p/11229389.html

 

  场上试图拿数位瞎搞,转移转不动。。

  震惊,竟然是n4的四维dp

  附赠一份和题解没什么不同但是加了贼快的快读板子才能998ms过的代码_(:з」∠)_

技术图片
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
typedef long long ll;
int n, m,t;
vector<pair<int, int> >rq[101];
const ll mod = 998244353;
ll d[101][101][101][2];


inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
char ch=nc();int sum=0;
while(!(ch>=0&&ch<=9))ch=nc();
while(ch>=0&&ch<=9)sum=sum*10+ch-48,ch=nc();
return sum;
}


int main()
{
    t=rd();
    while (t--) {
        n=rd();m=rd();
        int co = n;
        for (int i = 1; i <= n; i++) {
            rq[i].clear();
            rq[i].push_back({ i,1 });
        }
        for (int i = 1; i <= m; i++) {
            int l, x,r;
            l=rd();r=rd();x=rd();
            rq[r].push_back({ l,x });
        }
        memset(d, 0, sizeof(d));
        d[0][0][0][0] = 1;
        
        for(int now=1;now<=n;now++){
            bool gal = now & 1;
            for (int i = 0; i <= now; i++)
                for (int j = i; j <= now; j++)
                    for (int k = j; k <= now; k++)
                        d[i][j][k][gal] = 0;
        
            for(int i=0;i<=now;i++)
                for (int j = i; j <= now; j++)
                    for (int k = j; k <= now; k++) {
                        d[i][j][now - 1][gal] = (d[i][j][k][gal ^ 1] + d[i][j][now - 1][gal]) % mod;
                        d[j][k][now - 1][gal] = (d[i][j][k][gal ^ 1] + d[j][k][now - 1][gal]) % mod;
                        d[i][k][now - 1][gal] = (d[i][j][k][gal ^ 1] + d[i][k][now - 1][gal]) % mod;
                        d[i][j][k][gal] = (d[i][j][k][gal ^ 1] + d[i][j][k][gal]) % mod;
                    }
            
            for (int i = 0; i <= now; i++)
                for (int j = i; j <= now; j++)
                    for (int k = j; k <= now; k++)
                        for (auto p:rq[now])
                            if ((p.first <= i) + (p.first <= j) + (p.first <= k) + (p.first <= now) != p.second)
                                d[i][j][k][gal] = 0;
        }
        ll ans = 0;
        for (int i = 0; i <= n; i++)
            for (int j = i; j <= n; j++)
                for (int k = j; k <= n; k++)
                    ans = (ans + d[i][j][k][n & 1]) % mod;
        printf("%lld\\n", ans);

    }

    return 0;
}
Blank

  本来想不用vector,拿pair写了写,还真实现不了唉。。

以上是关于[补]2019HDU杭电多校第一场A的主要内容,如果未能解决你的问题,请参考以下文章

[2019杭电多校第一场][hdu6578]Blank

2019杭电多校第一场 Operation HDU - 6579

2019.07.222019杭电多校第一场

2019杭电多校第一场hdu6581 Vacation

[补]2019HDU杭电多校第五场H

2019 杭电多校第一场