[补]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写了写,还真实现不了唉。。
标签:p2,杭电多校,p1,ch,第一场,2019HDU,include,buf,101 来源: https://www.cnblogs.com/non-/p/11259568.html