BZOJ 1172 Balkan2007 Dream

阅读: 评论:0

BZOJ 1172 Balkan2007 Dream

BZOJ 1172 Balkan2007 Dream

提示:
1. 一个乘积如果要判断整除 k ,我们需要记录哪些量
2. 每一行最多取两个可以单独抽出来做 dp

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <map>using namespace std;
const int maxn = 210;int n , m , k , l , cnt;
int d[maxn][maxn] , t[maxn] , now[maxn] , g[maxn][11000];
map<int , int> dic; int redic[maxn] , trans[maxn][maxn];int main(int argc, char *argv[]) {cin>>n>>m>>k>>l;for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d" , g[i] + j);for(int i=1;i<=k;i++) if(k % i == 0) redic[++cnt] = i , dic[i] = cnt;for(int i=1;i<=cnt;i++) for(int j=1;j<=cnt;j++) trans[i][j] = dic[__gcd((int)((1LL*redic[i]*redic[j])%k) , k)];d[0][1] = 1;for(int i=1;i<=n;i++){memset(t , 0 , sizeof t);for(int j=1;j<=m;j++) t[dic[__gcd(g[i][j] , k)]]++;memcpy(now , t , sizeof t);if(1 < i && i < n) {for(int j=1;j<=cnt;j++) for(int k=1;k<=cnt;k++) (now[trans[j][k]] += t[j]*t[k]) %= l;for(int j=1;j<=cnt;j++) (now[trans[j][j]] -= t[j]) %= l;}for(int j=1;j<=cnt;j++) for(int k=1;k<=cnt;k++) (d[i][trans[j][k]] += d[i-1][j]*now[k]) %= l;}cout<<(d[n][cnt]+l)%l<<endl;return 0;
}

di 记录目前 gcd(乘积,k)==i 的方案数 , i 这个值的数量级是102级别的
那么我们就可以把相同 gcd 值的数归类,那么整体复杂度就降到了 106 级别。

本文发布于:2024-02-04 22:16:58,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170717648160098.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:BZOJ   Dream
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23