入阵曲 (组合数 余数统计)
来源:互联网 发布:淘宝华佗大药房怎么样 编辑:程序博客网 时间:2024/05/24 06:39
入阵曲
10.24
思路:
明显的n3复杂度,考虑n2卡住上下界,组合数计数优化,由于模数比较小,我们维护了每一列的前缀之后,就可以O(1)计算固定上下界的前缀矩形的值了。记录每个前缀矩形modK的余数,记录每种余数有多少个,同种余数的前缀矩形相减就是合法。清空不要用memset会T。。。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <algorithm>#define LL long long#define N 410using namespace std;int n, m, k, idc=0;int mp[N][N], res[N];int cnt[1000010];LL sum[N][N];LL ans=0;inline int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x * f;}int main() { freopen ("rally.in", "r", stdin); freopen ("rally.out", "w", stdout); scanf("%d%d%d", &n, &m, &k); for(register int i=1; i<=n; i++){ for(register int j=1; j<=m; j++){ mp[i][j] = read(); sum[i][j] = sum[i-1][j] + mp[i][j]; } } for(register int i=0; i<n; i++){ for(register int j=i+1; j<=n; j++){ LL cc = 0; for(register int p=1; p<=m; p++){ cc = ( (cc + sum[j][p] - sum[i][p]) % k + k ) % k; cnt[cc]++; res[++idc] = cc; } cnt[0]++; for(register int x=1; x<=idc; x++){ int d = res[x]; ans += cnt[d] * (cnt[d] - 1) / 2; cnt[d] = 0; } cnt[0] = 0; idc = 0; } } cout << ans << endl; return 0;}
阅读全文
0 0
- 入阵曲 (组合数 余数统计)
- BZOJ 4403: 序列统计 (组合数 Lucas 数论推导)
- SQL统计构成组合数、未构成组合数
- 【BZOJ4403】【lucas】【组合数】序列统计 题解
- 1257: [CQOI2007]余数之和sum(数学分段统计)
- 组合数(nyoj32)
- 组合数(dfs)
- 组合数(dfs)
- 组合数 (Lucas)
- 组合数(未完)
- sumcomb (组合数)
- uva1635(组合数)
- 组合数(dfs)
- poj 3252 (组合数)
- hdu 4655 (组合数)
- 求组合数(数学)
- acm-组合数(prev_permutation)
- Catalan数(组合数学)
- 第二章 SQL命令参考-DELETE
- 浅析java中静态方法,非静态方法和构造方法的执行顺序问题
- 洛谷 [P1024]一元三次方程求解
- 1031. 查验身份证(15)--PAT乙级
- 大大大
- 入阵曲 (组合数 余数统计)
- 沉浸式(非纯色)
- how to compile kinfu_remake with cuda 9.0 opencv2.4.13.4
- Codeforces 877D
- Deep Neural Networks for YouTube Recommendations
- java-JDBC-ResultSet详解(java数据库操作)
- JS中时间戳转日期格式(YYYY-MM-dd HH:mm:ss)
- css中给div加边框
- 计算机网络第四次作业