2019牛客多校 Round2
Solved:2
Rank:136
E MASE
题意:给一个N x M的01矩阵(M <= 10) 1表示墙 每个点可以往左右下走
一个修改操作 把之前矩阵中某个位置的数取反
一个查询操作 查询从第一行的一个位置走到第n行一个位置的方案数
题解:做的第一道动态DP的题 由于一些奇特的性质
DP的转移可以用矩阵表示 矩阵乘法有结合率 线段树可以维护矩阵的区间积
然后就这样了....
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7;int n, m, t; char s[100005][12]; struct martix {ll c[10][10]; }sum[400005];martix mul(martix x, martix y) {martix res;for(int i = 0; i < m; i++)for(int j = 0; j < m; j++) res.c[i][j] = 0;for(int i = 0; i < m; i++)for(int k = 0; k < m; k++)for(int j = 0; j < m; j++)res.c[i][j] = (res.c[i][j] + x.c[i][k] * y.c[k][j] % mod) % mod;return res; }martix fun(char a[12]) {martix res;for(int i = 0; i < m; i++)for(int j = 0; j < m; j++) res.c[i][j] = 0;for(int i = 0; i < m; i++) {if(a[i] == '0') {int l = i, r = i;while(l - 1 >= 0 && a[l - 1] == '0') l--;while(r + 1 < m && a[r + 1] == '0') r++;for(int j = l; j <= r; j++) res.c[i][j] = 1;}}return res; }void pushup(int rt) {sum[rt] = mul(sum[rt << 1], sum[rt << 1 | 1]); }void build(int l, int r, int rt) {if(l == r) {sum[rt] = fun(s[l]);return;}int m = l + r >> 1;build(l, m, rt << 1);build(m + 1, r, rt << 1 | 1);pushup(rt); }void update(int k, int l, int r, int rt) {if(l == r) {sum[rt] = fun(s[k]);return;}int m = l + r >> 1;if(k <= m) update(k, l, m, rt << 1);else update(k, m + 1, r, rt << 1 | 1);pushup(rt); }int main() {scanf("%d%d%d", &n, &m, &t);for(int i = 1; i <= n; i++) {scanf("%s", s[i]);}build(1, n, 1);while(t--) {int opt, a, b;scanf("%d%d%d", &opt, &a, &b);if(opt == 1) {if(s[a][b - 1] == '0') s[a][b - 1] = '1';else s[a][b - 1] = '0';update(a, 1, n, 1);} else if(opt == 2) {printf("%lld\n", sum[1].c[a - 1][b - 1]);}}return 0; }
E MASE
F Partition problem
签到题
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans; int n;ll q[30][30]; ll sum[30]; int id[30]; void dfs(int now, int tot, ll val) {if(tot == n) {ans = max(ans, val);return;}if(now > n * 2) return;for(int i = now; i <= n * 2; i++) {ll tmp = val + sum[i];for(int j = 1; j <= tot; j++) tmp -= q[i][id[j]] * 2LL;tot++;id[tot] = i;dfs(i + 1, tot, tmp);tot--;}return; }int main() {ans = 0;scanf("%d", &n);for(int i = 1; i <= n * 2; i++) {for(int j = 1; j <= n * 2; j++) {scanf("%lld", &q[i][j]);sum[i] += q[i][j];}}dfs(1, 0, 0);printf("%lld\n", ans);return 0; }
F Partition problem
转载于:https://www.cnblogs.com/lwqq3/p/11218680.html
2019牛客多校 Round2相关推荐
- 2019牛客多校第一场
2019牛客多校第一场 题号 题目 知识点 A Monotonic Matrix B Symmetric Matrix C Fluorescent 2 D Two Graphs E Removal F ...
- 2019牛客多校训练第十场F Popping Balloons
2019牛客多校训练第十场F Popping Balloons 题意:二维平面内给你若干个点,然后你可以在x轴和y轴分别射三枪(每一枪的间隔是R),问最多能射掉多少气球. 题解:贪心.这个应该只能算作 ...
- 2019牛客多校第九场AThe power of Fibonacci(广义BM)
2019牛客多校第九场AThe power of Fibonacci(广义BM) 题目大意 求斐波那契数列m次方的前n项和 解题思路 显然,斐波那契的m次方前缀和依然是线性递推,因此考虑用exBM求解 ...
- 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数
目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...
- Knapsack Cryptosystem(2019牛客多校折半查询)
链接:https://ac.nowcoder.com/acm/contest/889/D 来源:牛客网 Amy asks Mr. B problem D. Please help Mr. B to s ...
- Quadratic equation(二次剩余)2019牛客多校第九场
链接:https://ac.nowcoder.com/acm/contest/889/B 来源:牛客网 题目描述 Amy asks Mr. B problem B. Please help Mr. B ...
- [2019牛客多校训练第3场]Median
链接:https://ac.nowcoder.com/acm/contest/883/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- 2019牛客多校训练营第一场 H题 HOR 题解
题目描述: 输入描述: 输出描述: 示例1: 题解: 更多问题可关注牛客竞赛区,一个刷题.比赛.分享的社区. 传送门:https://ac.nowcoder.com/acm/contest/discu ...
- 2019牛客多校 第七场 B Irreducible Polynomial 多项式因式分解判断
链接:https://ac.nowcoder.com/acm/contest/887/B 来源:牛客网 Irreducible Polynomial 时间限制:C/C++ 1秒,其他语言2秒 空间限制 ...
最新文章
- Android环境搭建和Android HelloWorld—Android开发环境搭建
- 《数学之美》第10章 PageRank--Google的民主表决网页排名技术
- Python基础语法精心总结!看完都知道的可以往下继续学习了
- VisualSVN Server Manager创建版本库以及TortoiseSVN的使用
- android root 挂载分区,adb — adb disable-verity, adb remount 实现重新挂载system分区为可读写分区...
- 影像科dsa为什么必须买维修保险_了解什么是DSA,看这篇就够了
- IPv6转换服务正式发布
- java泛型和注解,泛型 · 注解和泛型 · 看云
- deque冰淇淋_用冰淇淋解释组合爆炸:如何添加一点并获得很多
- Android笔记 ANR Application Not Response
- 剑指Offer之数组中重复的数字
- 抽象工厂模式---创建型
- AI早教产业鄙视链,你处在哪一层?
- oracle视图在查询里,oracle视图
- 10个重要的算法C语言实现源代码:拉格朗日,牛顿插值,高斯,龙贝格,牛顿迭代,牛顿-科特斯,雅克比,秦九昭,幂法,高斯塞德尔
- SHoj 420 购买装备
- 详解VMware CentOS网络配置
- 经典影视剧《大宋提刑官》——老剧重看,再添心得
- 机器学习——关联规则
- No suspicious code found. 1 files processed in 'File '
热门文章
- cluster oracle修改,Oracle 修改集群的资源属性(依赖关系)
- java发布rest服务器_ArcGIS Server 10 Java 版的Rest服务的部署方法
- JavaScript内置对象→对象、系统函数、Date日期对象、String字符串对象、Math对象、Number数字对象、Object对象、Boolean对象、Error对象
- SQL Server高级查询之子查询(子查询非典型应用)
- 无类域间路由CIDR
- bzoj 4001: [TJOI2015]概率论(找规律)
- 关于YOLOv3的文章
- (一)pscc学习笔记
- tf.get_variable与tf.variable_scope
- 8255工作方式一选通输入——A口(含时序图分析)