洛谷P3230 比赛

时间:2023-03-10 06:59:34
洛谷P3230 比赛

emmmmmm,这个之前讲课的原题居然出到比赛里了。

我怒肝2h+然后A了此题,结果还是被某高一巨佬吊打......


题意:n个球队两两比赛,胜得3分,败得0分,平得1分。

现有一个总分表,求问可能的比赛情况。

解:

发现答案与球队的顺序无关,于是按照分数排序。

然后发现可能搜到重复状态,可以记忆化吗?可以拿hash记忆化......(毒瘤)。

然后枚举当前第一队与其他队的胜负情况,这里我又写了个DFS(毒瘤 << 1)。

然后没了......注意这道题实现起来满满的毒瘤。

 #include <cstdio>
#include <algorithm> const int N = , B = , OM = , MO = 1e9 + ; struct Node {
int t, a[N], h, nex, ans;
inline void geth() {
h = ;
for(int i = ; i <= t; i++) {
h = h * B % OM + a[i];
while(h >= OM) {
h -= OM;
}
}
return;
}
inline bool operator ==(const Node &d) const {
if(t != d.t) {
return ;
}
for(int i = ; i <= t; i++) {
if(a[i] != d.a[i]) {
return ;
}
}
return ;
}
inline void st() {
std::sort(a + , a + t + );
std::reverse(a + , a + t + );
/*while(!a[t] && t) {
t--;
}*/
return;
}
inline void out() {
for(int i = ; i <= t; i++) {
printf("%d ", a[i]);
}
puts("");
return;
}
}node[], temp; int top; int head[OM]; inline int find(Node x) {
int h = x.h;
for(int i = head[h]; i; i = node[i].nex) {
if(node[i] == x) {
return node[i].ans;
}
}
return -;
} inline void insert(Node sta) {
int h = sta.h;
node[++top] = sta;
node[top].nex = head[h];
head[h] = top;
return;
} int DFS(Node, int); int DFSp(Node sta, int k, int lw) { // a[1] -> a[k] ing if(k > sta.t) {
if(sta.a[]) {
return ;
}
std::swap(sta.a[], sta.a[sta.t]);
sta.t--;
return DFS(sta, lw);
}
if((sta.t - k + ) * < sta.a[]) {
return ;
} int ans = ;
if(sta.a[k] >= ) { // 1 lose
sta.a[k] -= ;
ans += DFSp(sta, k + , lw - );
ans %= MO;
sta.a[k] += ;
}
if(sta.a[] >= ) { // 1 win
sta.a[] -= ;
ans += DFSp(sta, k + , lw - );
ans %= MO;
sta.a[] += ;
}
if(sta.a[] >= && sta.a[k] >= ) { // both
sta.a[] -= ;
sta.a[k] -= ;
ans += DFSp(sta, k + , lw);
ans %= MO;
}
return ans;
} int DFS(Node sta, int last) { sta.st();
if(sta.t == ) {
if(!last && !sta.a[]) {
return ;
}
return ;
} sta.geth();
int t = find(sta);
if(t > -) {
return t;
} int ans = DFSp(sta, , last); sta.ans = ans;
insert(sta); return ans;
} int main() { int n, tot = ;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &temp.a[i]);
tot += temp.a[i];
} temp.t = n;
int ans = DFS(temp, tot - (n - ) * n); printf("%d", ans); return ;
}

AC代码

注意到洛谷rank1的搜索方法和我大同小异,但是速度吊打我14.75倍(毒瘤)。他以为这个东西可以用LL装下(真TM的可以!!!我是沙雕!),然后我就SB的又存又传了一大堆数组......